-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounting_Divisors.cpp
More file actions
68 lines (59 loc) · 987 Bytes
/
Counting_Divisors.cpp
File metadata and controls
68 lines (59 loc) · 987 Bytes
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
/*
AUTHOR: Antarikshya Mitra
TIME: 1:24 AM - 2:19 AM
PROBLEM NO:- CSES Counting Divisors
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MOD = 1e9 + 7;
vector<int> sieve(1e7+1);
void precompute() {
for(int i=2;i*i<sieve.size();i++)
{
if(sieve[i]==i) {
for(int j=i*i;j<sieve.size();j+=i)
{
if(sieve[j]==j) sieve[j]=i;
}
}
}
}
void solve(vector<int> arr)
{
int n = arr.size();
for(int i=0;i<n;i++)
{
int x = arr[i];
int res=1;
while(x>1)
{
int alpha = 0;
int spf = sieve[x];
while(x%spf==0)
{
alpha++;
x/=spf;
}
res*=(alpha+1);
}
cout<<res<<endl;
}
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
for(int i=1;i<sieve.size();i++)
sieve[i]=i;
precompute();
cin>>n;
vector<int> arr(n);
for (auto &a:arr)
cin>>a;
solve(arr);
return 0;
}