求因数和
程序代码:
//我都二分两个了,怎么一直T呢 http://218.194.91.48/acmhome/problemdetail.do?&method=showdetail&id=1322 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef __int64 LL; const int MAXN=1<<16; int k=0; LL pri[MAXN],cnt[MAXN],prime[MAXN],flag[MAXN]; void fun() { int i,j; for(i=2;i<MAXN;++i){ if(!flag[i]){ for(j=i*2;j<MAXN;j+=i) flag[j]=1; } } for(i=2;i<MAXN;++i) if(!flag[i]) prime[k++]=i; } LL pow(LL a,LL b) { LL tmp=1; while(b>0){ if(b&1) tmp*=a; b>>=1,a*=a; } return tmp; } LL mul(LL a,LL b) { LL tmp=0; while(b>0){ if(b&1) tmp+=a; a+=a,b>>=1; } return tmp; } LL sum(LL p,LL n) { LL tmp=pow(p,n+1); return (tmp-1)/(p-1); } int main() { fun(); LL i,n,t=0; while(~scanf("%I64d",&n)){ memset(pri,0,sizeof(pri)); memset(cnt,0,sizeof(cnt)); for(i=0;i<k;++i){ if(n%prime[i]==0){ pri[t]=prime[i]; while(n%prime[i]==0){ cnt[t]++; n/=prime[i]; } t++; } } LL count=1; for(i=0;i<t;++i) count=mul(count,sum(pri[i],cnt[i])); printf("%I64d\n",count); } return 0; }
[ 本帖最后由 cb_1212 于 2012-7-12 10:55 编辑 ]