- 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++
- Find largest sum of digits in all divisors of n in C++
- First triangular number whose number of divisors exceeds N in C++
- Count of divisors having more set bits than quotient on dividing N in C++
- Find maximum N such that the sum of square of first N natural numbers is not more than X in C++
- C++ Program for Common Divisors of Two Numbers?
- 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?
- Find maximum N such that the sum of square of first N natural numbers is not more than X in Python
- Count divisors of array multiplication in C++
- C++ Program for Area Of Square after N-th fold
- Closest Divisors in C++
- Four Divisors in C++

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

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.

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; }

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

5

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

Advertisements