# Bzoj2818 gcd

Posted by yjjr's blog on February 6, 2018

Description

Input

Output

Sample Input

4

Sample Output

4

HINT

hint

1<=N<=10^7

1.
x为质数时，phi[x]=x-1

2.i mod x==0时（x为质数）phi[x*i]=phi[i]*j

3.当i mod x0时（x为质数）phi[x*i]=phi[i]*(j-1)

Code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define mem(x,num) memset(x,num,sizeof x)
#define LL long long
using namespace std;
{
LL f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const LL maxn=1e7+6;
LL n,prime[maxn],top,ans,phi[maxn];
bool not_prime[maxn];
void shaker()
{
int j;phi[1]=1;
rep(i,2,n){
if(!not_prime[i]){prime[++top]=i;phi[i]=i-1;}
for(j=1;j<=top&&i*prime[j]<=n;j++){
not_prime[prime[j]*i]=1;
if(i%prime[j]==0){phi[prime[j]*i]=phi[i]*prime[j];break;}
phi[prime[j]*i]=phi[i]*(prime[j]-1);
}
}
}
int main()
{