Editorial
Let be the number of divisors of . Obviously, .
Let be a prime integer. Then has two divisors: and . Therefore, .
Let be a power of a prime number. Then has divisors: . Hence, .
Let . Consider two sets: and
Any divisor of the number can be represented in the form , where . A divisor from can be chosen in ways, and a divisor from can be chosen in ways. Therefore, a divisor can be formed in ways.
Decompose the number into its prime factors: . The number of divisors of is equal to
Example
The number has divisors: .
Let's decompose the number into its prime factors:
Therefore
Subtracting two divisors ( and ), we get the answer: divisors.
Algorithm realization
The function CountDivisors decomposes the number into its prime factors and calculates the number of its divisors .
int CountDivisors(int n) { int c, i, res = 1; for(i = 2; i * i <= n; i++) { if (n % i == 0) { c = 0; while(n % i == 0) { n /= i; c++; } res *= (c + 1); } } if (n > 1) res *= 2; return res; }
The main part of the program. Read the value of .
scanf("%d",&n);
Calculate and print the answer. From the total number of divisors subtract two divisors: and the number itself.
printf("%d\n",CountDivisors(n)-2);
Python realization
import math
The function CountDivisors decomposes the number into its prime factors and calculates the number of its divisors .
def CountDivisors(n): res = 1; for i in range(2, int(math.sqrt(n)) + 1): if (n % i == 0): c = 0 while (n % i == 0): n //= i c += 1 res *= (c + 1); if (n > 1): res *= 2; return res;
The main part of the program. Read the value of .
n = int(input())
Calculate and print the answer. From the total number of divisors subtract two divisors: and the number itself.
print(CountDivisors(n) - 2)