codevs4415
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define LL long long
LL a,b,c,n;
LL phi(LL x)//求单个欧拉函数的算法
{
LL t=x;
for (LL i=2;i*i<=x;i++) //注意i*i<=x的表示
if (x % i==0)
{
t=t/i*(i-1);
while (x %i ==0) x/=i;
}
if (x>1) t=t/x*(x-1);//这句保证最后的质数被算到
return t;
}
LL sumphi(LL x)
{
LL ans=0;
for (LL i=1;i*i<=x;i++)
if (x % i==0)
{
ans+=phi(i);
if (i*i<x) ans+=phi(x / i);
}
return ans;
}
LL sumgcd()
{
LL ans=0;
for (LL i=1;i*i<=n;i++)
if (n %i ==0)
{
ans+=(LL)i*phi(n/i);
if (i*i<n) ans+=(LL)(n/i)*phi(i);
}
return ans;
}
int main()
{
scanf("%lld", &n);
a=phi(n);
b=sumgcd();
c=sumphi(n);
printf("%lld", a+b % c);
system("pause");
return 0;
}