-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathcses-counting-divisors.cpp
69 lines (56 loc) · 1.32 KB
/
cses-counting-divisors.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
STATEMENT:
Given n integers, your task is to report for each integer the number of its divisors.
For example, if x=18, the correct answer is 6 because its divisors are 1,2,3,6,9,18.
Input
The first input line has an integer n: the number of integers.
After this, there are n lines, each containing an integer x.
Output
For each integer, print the number of its divisors.
Constraints
1 <=n<=10^5
1 <= x <= 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
number of divisors is the sum of the powers of the prime factors.
*/
void solve()
{
int number;
cin >> number;
vector<int> powersOfPrimeFactors;
for (int i = 2; i * i<=number; i++)
{
if (number % i == 0)
{
int power = 0;
while (number % i == 0)
{ power++;
number /= i;
}
powersOfPrimeFactors.push_back(power);
}
}
if (number != 1)
powersOfPrimeFactors.push_back(1);
int numberOfDivisors = 1;
int u=powersOfPrimeFactors.size();
for (int i=0;i<u;i++)
{
numberOfDivisors *= (powersOfPrimeFactors[i] + 1);
}
cout << numberOfDivisors << endl;
}
int main()
{
int t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}