// Verdict :: Accepted
// Time :: 0.119
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <cctype>
#include <sstream>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#define sf scanf
#define pf printf
#define sfint scanf ("%d %d",&a,&b)
#define sfl scanf ("%ld %ld",&a,&b)
#define sfll scanf ("%lld %lld",&a,&b)
#define sfd scanf ("%lf %lf",&a,&b)
#define sff scanf ("%f %f",&a,&b)
#define lp1(i,n) for(i=0;i<n;i++)
#define lp2(i,n) for(i=1;i<=n;i++)
#define LL long long
#define L long
#define mem(c,v) memset(c,v,sizeof(c))
#define ui unsigned int
#define ull unsigned long long int
#define nl puts("")
#define sq(x) ((x)*(x))
#define MX 1000005
#define N 100
#define MOD 10000000007
#define pb push_back
#define pi acos(-1.0)
#define sz size()
#define gc getchar ()
#define ps push
#define clr clear
#define inf 2147483647
#define bn begin()
#define ed end()
using namespace std;
LL prime[MX+15],p[MX+15],plen=0;
LL setbit(LL n, LL pos)
{
n=n|(1<<pos);
return n;
}
LL checkbit(LL n, LL pos)
{
n=n&(1<<pos);
return n;
}
void seieve(LL n)
{
LL i,j,x=sqrt(n);
prime[0]=setbit(prime[0],0);
prime[0]=setbit(prime[0],1);
for(i=4;i<=n;i+=2)
{
prime[i>>5]=setbit(prime[i>>5],i&31);
}
for(i=3;i<=x;i+=2)
{
if(!checkbit(prime[i>>5],i&31))
{
for(j=i*i;j<=n;j+=i)
{
prime[j>>5]=setbit(prime[j>>5],j&31);
}
}
}
for(i=1;i<=n;i++)
{
if(!checkbit(prime[i>>5],i&31))
{
p[plen++]=i;
}
}
}
LL divisors(LL n)
{
LL i,j,phi=n;
for(i=0; i<=plen and sq(p[i]) <= n ; i++)
{
if(!(n%p[i]))
{
phi-=phi/p[i];
while(!(n%p[i]))
{
n/=p[i];
if(n==0 or n==1) break;
}
}
}
if(n>1)
{
phi-=phi/n;
}
//pf("%lld",phi);
return phi;
}
int main()
{
seieve(MX);
//for(LL i=0;i<plen;i++) cout << p[i] << " ";
//divisors();
LL n;
while(sf("%lld",&n)==1 and n)
{
if(n==1)
{
pf("0\n");
continue;
}
LL res=divisors(n);
if(res<=0)
{
pf("%lld\n",n);
}
else
{
pf("%lld\n",res);
}
}
return 0;
}
Comments
Post a Comment