#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
// i64 gcd(i64 a,i64 b){return b?gcd(b,a%b):a;}
i64 gcd(i64 _a, i64 _b)
{
if (!_a || !_b)
{
return max(_a, _b);
}
i64 _t;
while ((_t = _a % _b))
{
_a = _b;
_b = _t;
}
return _b;
}
i64 ext_gcd (i64 _a, i64 _b, i64 &_x, i64 &_y)
{
if (!_b)
{
_x = 1;
_y = 0;
return _a;
}
i64 _d = ext_gcd (_b, _a % _b, _x, _y);
i64 _t = _x;
_x = _y;
_y = _t - _a / _b * _y;
return _d;
}
i64 invmod (i64 _a, i64 _p)
{
i64 _ans, _y;
ext_gcd (_a, _p, _ans, _y);
_ans < 0 ? _ans += _p : 0;
return _ans;
}
const int maxn = 100000;
vector<int>p;
int n;
bool isp(int x)
{
int temp = sqrt(double(x));
for(int i=0;i<p.size();i++)
{
if(p[i] > temp)
{
return true;
}
if(!(x%p[i]))
{
return false;
}
}
return true;
}
void init()
{
p.clear();
p.pb(2);
for(int i=3;i<maxn;i++)
{
if(isp(i))
{
p.pb(i);
}
}
return ;
}
int phi(int x)
{
int ans = 1;
int temp;
int num;
for(int i=0;p[i]*p[i]<=x;i++)
{
temp = 0;
while(x%p[i]==0)
{
x/=p[i];
if(!temp)
{
temp = p[i]-1;
}
else
{
temp *= p[i];
}
}
if(temp)
{
ans*=temp;
}
}
if(x!=1)
{
ans*=x-1;
}
return ans;
}
int main()
{
init();
while(cin>>n)
{
if(!n) return 0;
cout<<phi(n)<<endl;
}
return 0;
}
pku2407 Relatives
最新推荐文章于 2018-08-12 10:51:44 发布