[SDOI2012]Longge的问题 欧拉反演_欧拉函数

Code:

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;
typedef long long ll;
void setIO(string a){freopen((a+".in").c_str(),"r",stdin);}
int main(){
	//setIO("input");
	ll n,ans;
	while(scanf("%lld",&n)!=EOF){
		ans=n;
		for(ll i=2;i<=(ll)sqrt(n*1.0);++i){
			int a=i;
			if(n%i==0)
			{
				int p=0;
				while(n%i==0){
					++p;
					n/=i;
				}
				ans+=ans*p*(a-1)/a;
			}
		}
		if(n!=1) ans+=ans*(n-1)/n;
		printf("%lld
",ans);
	}
	return 0;
}

  

原文地址:https://www.cnblogs.com/guangheli/p/9889904.html