- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- 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 Articles
- Minimum number of Square Free Divisors in C++
- Count divisors of n that have at-least one digit common with n in Java
- 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 the numbers < N which have equal number of divisors as K in C++
- Count of divisors having more set bits than quotient on dividing N in C++
- C++ Program for Common Divisors of Two Numbers?
- C++ Program for the Common Divisors of Two Numbers?
- Closest Divisors in C++
- Four Divisors in C++
- Count divisors of array multiplication in C++

Advertisements