"The main topic"
Find out ∑GCD (i, N) (1<=i <=n).
Ideas
For X=AK,Y=BK, gcd (A, B) =1 must have gcd (x, y) = 1. All factors of the enumeration N, ∑GCD (i, N) =∑ (φ (n/k) *k) (k| N).
*n factor and must be in the n^ (1/2) time to find out, otherwise it will tle.
Code
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 /*Note Data range*/8 Const intmaxn=10010;9 ll N;Ten ll FACTOR[MAXN]; One A voidGet_factor () - /*all quality factors must be calculated within n^ (1/2) time, otherwise te*/ - { theMemset (Factor,0,sizeof(factor)); - ll I; - for(i=1; i*i<n;i++) - { + if(n%i==0) - { +factor[++factor[0]]=i; Afactor[++factor[0]]=n/i; at } - } - if(i*i==n) factor[++factor[0]]=i; - } - - ll Eular (ll K) in { -ll res=K; to for(LL p=2;p *p<=k;p++) + { - if(k%p==0) the { *res=res-res/p; $ while(k%p==0) k/=p;Panax Notoginseng } - } the if(k>1) res=res-res/K; + /*idea K may be greater than 0 and must be subtracted*/ A returnRes; the } + - voidInit () $ { $scanf"%d",&n); - } - the ll Get_ans () - {Wuyill result=0; the for(LL i=1; i<=factor[0];i++) -Result+=eular (N/factor[i]) *Factor[i]; Wu returnresult; - } About $ intMain () - { - init (); - get_factor (); ACout<<get_ans () <<Endl; + return 0; the}
The mathematical problem of "Euler function" Bzoj2190-[sdoi2012]longge