# bzoj2705: [SDOI2012]Longge的问题 欧拉定理

/**************************************************************
Problem: 2705
User: walfy
Language: C++
Result: Accepted
Time:56 ms
Memory:1288 kb
****************************************************************/

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double g=10.0,eps=1e-12;
const int N=100000+10,maxn=1000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

ll eu(ll n)
{
ll ans=n;
for(ll i=2;i*i<=n;i++)
{
if(n%i==0)
{
ans=ans/i*(i-1);
while(n%i==0)n/=i;
}
}
if(n!=1)ans=ans/n*(n-1);
return ans;
}
int main()
{
ll n;scanf("%lld",&n);
ll ans=0;
for(int i=1;i*i<=n;i++)
{
if(n%i==0)
{
ans+=i*eu(n/i);
if(i*i!=n)ans+=n/i*eu(i);
}
}
printf("%lld\n",ans);
return 0;
}
/***********************

***********************/

posted @ 2018-07-04 11:56  walfy  阅读(123)  评论(0编辑  收藏  举报