- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Divisors of n-square that are not divisors of n in C++ Program

In this tutorial, we are going to write a program that finds the divisors count of n-square and not n.

It's a straightforward problem. Let's see the steps to solve the problem.

Initialize the number n.

Initialize a counter for divisors.

Iterate from 2 to n^2n2.

If the n^2n2 is divisible by the current number and nn is not divisible by the current number, then increment the count.

Print the count.

## Example

Let's see the code.

#include <bits/stdc++.h> using namespace std; int getNumberOfDivisors(int n) { int n_square = n * n; int divisors_count = 0; for (int i = 2; i <= n_square; i++) { if (n_square % i == 0 && n % i != 0) { divisors_count++; } } return divisors_count; } int main() { int n = 6; cout << getNumberOfDivisors(n) << endl; return 0; }

## Output

If you execute the above program, then you will get the following result.

5

## Conclusion

If you have any queries in the tutorial, mention them in the comment section.

- Related Questions & Answers
- Count divisors of n that have at-least one digit common with n in Java
- Minimum number of Square Free Divisors in C++
- Queries to Print All the Divisors of n using C++
- Find largest sum of digits in all divisors of n in C++
- First triangular number whose number of divisors exceeds N in C++
- Find the number of divisors of all numbers in the range [1, n] in C++
- Find the largest good number in the divisors of given number N in C++
- Find sum of divisors of all the divisors of a natural number in C++
- Count of divisors having more set bits than quotient on dividing N in C++
- C++ Program for Common Divisors of Two Numbers?
- Find maximum N such that the sum of square of first N natural numbers is not more than X in C++
- Count the numbers < N which have equal number of divisors as K in C++
- Integers have sum of squared divisors as perfect square in JavaScript
- C++ Program for the Common Divisors of Two Numbers?
- Count divisors of array multiplication in C++

Advertisements