[poj 2480] Longge's problem 解题报告 (欧拉函数)
题目链接:http://poj.org/problem?id=2480
题目大意:
题解:
我一直很欣赏数学题完美的复杂度
#include<cstring> #include<algorithm> #include<cstdio> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const int N=(1<<31)+15; ll n; int main() { //printf("%lld\n",phi(3)); while (scanf("%lld",&n)!=EOF) { ll ans=n; for (ll i=2;i*i<=n;i++) { if (n%i) continue; //if (i==1) ans++; ll j=0; while (n%i==0) n/=i,j++; ans/=i; ans*=(i-1)*j+i; } if (n>1) { ans/=n; ans*=2*n-1; } printf("%lld\n",ans); } return 0; }
星星之火,终将成燎原之势