-
Notifications
You must be signed in to change notification settings - Fork 16
/
CountTheInteger.cpp
65 lines (57 loc) · 1.11 KB
/
CountTheInteger.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rep1(i,a,n) for(int i=a;i<=n;i++)
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define fast_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll phi[1000001];
ll countDiv(ll n)
{
ll cnt=0;
for(int i=1;i<=sqrt(n);i++)
{
if(n%i==0)
{
if(n/i==i)
cnt++;
else
cnt+=2;
}
}
return cnt;
}
void Totient(int n)
{
for (int i=1; i<=n; i++)
phi[i] = i;
for (int p=2; p<=n; p++)
{
if (phi[p] == p)
{
phi[p] = p-1;
for (int i = 2*p; i<=n; i += p)
{
phi[i] = (phi[i]/p) * (p-1);
}
}
}
}
int main()
{
fast_io
ll n,q;
cin>>q;
Totient(1000001);
while(q--)
{
cin>>n;
ll f=countDiv(n);
cout<<n-f-phi[n]+1<<"\n";
}
return 0;
}