-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEULERPHI.cpp
More file actions
41 lines (39 loc) · 862 Bytes
/
EULERPHI.cpp
File metadata and controls
41 lines (39 loc) · 862 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
//
// Author : Manish Sharma
// SPOJ : EULER TOTIENT FUNCTION
// Problem : http://www.spoj.com/problems/ETF/
//
#include<bits/stdc++.h>
#define s(a) scanf("%d",&a)
#define ss(a) scanf("%s",a)
#define LIM 1000000
using namespace std;
typedef long long int ll;
int etf[1000010];
void precomp()
{
int i,j;
/*** Generate Euler Totient Function ***/
for(i=1;i<=LIM;i++)etf[i] = i;
for(i=2;i<=LIM;i++)
if(etf[i] == i)
for(j=2*i;j<=LIM;j+=i)
etf[j] = etf[j]-(etf[j]/i);
for(i=2;i<=LIM;i++)
if(etf[i]==i)
etf[i] = i-1;
/*** Generate Euler Totient Function ***/
}
int main()
{
int t,n;
ll ans;
precomp();
s(t);
while(t--)
{
s(n);
printf("%d\n",etf[n]);
}
return 0;
}