orz教主的解法实在太神了
直接贴题解
1 #include<bits/stdc++.h> 2 #define inc(i,l,r) for(int i=l;i<=r;i++) 3 #define dec(i,l,r) for(int i=l;i>=r;i--) 4 #define link(x) for(edge *j=h[x];j;j=j->next) 5 #define mem(a) memset(a,0,sizeof(a)) 6 #define inf 1e9 7 #define ll long long 8 #define succ(x) (1<<x) 9 using namespace std; 10 ll read(){ 11 ll x=0,f=1;char ch=getchar(); 12 while(!isdigit(ch)){if(ch==‘-‘)f=-1;ch=getchar();} 13 while(isdigit(ch))x=x*10+ch-‘0‘,ch=getchar(); 14 return x*f; 15 } 16 ll n,ans,t,s; 17 int main(){ 18 // freopen("data.in","r",stdin); 19 n=read();ans=1; 20 inc(i,2,(int)sqrt(n))if(n%i==0){ 21 if(n==1)break; 22 for(t=1,s=0;n%i==0;s++)n/=i,t*=i; 23 ans*=(s+1)*t-s*t/i; 24 } 25 if(n!=1)ans*=n+n-1; 26 printf("%lld",ans); 27 return 0; 28 }
时间: 2024-10-07 07:48:02