2705: [Sdoi2012]longge's question
Time Limit:20 Sec
Memory limit:256 MB
Topic Connection
http://www.lydsy.com/JudgeOnline/problem.php?id=2705
Description
Longge is very good at maths and he is very happy to challenge difficult math problems. Now the problem is: Given an integer N, you need to ask for ∑GCD (i, N) (1<=i <=n).
Input
An integer that is n.
Output
An integer, for the answer that is asked.
Sample Input
6
Sample Output
15
HINT
Test instructions
The following:
Puzzle: http://hzwer.com/3470.html
∑GCD (I,n) (1<=i<=n) is required in the title.
Enumeration N of the approximate k, so that s (k) to meet gcd (M,n) =k, (1<=m<=n) m, then Ans=sigma (K*s (k)) (k is an approximate number of n)
Because GCD (m,n) =k, so gcd (m/k,n/k) = 1, so s (k) =euler (n/k)
Phi can find out in the time of the radical
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<bitset>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200051#defineMoD 10007#defineEPS 1e-9intNum;//const int INF=0X7FFFFFFF; //нчоч╢сConst intinf=0x3f3f3f3f; inline ll read () {ll x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}//**************************************************************************************ll N;intM;ll Phi (ll x) {ll T=x; for(LL i=2; i<=m;i++) { if(x%i==0) {T=t/i* (I-1); while(x%i==0) x/=i; } } if(x>1) t=t/x* (x1); returnt;}intMain () {CIN>>N; ll ans=0; M=sqrt (n); for(intI=1; I<=sqrt (n); i++) { if(n%i==0) {ans+=i*phi (n/i); if(i*i<N) Ans+ = (ll) (n/i) *Phi (i); }} cout<<ans<<Endl;}
Bzoj 2705: [Sdoi2012]longge's Problem GCD