题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2052
2052: Pku1777 Vivian
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 28 Solved: 14
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Sample Output
HINT
Source
梅森素数。。。
没写这道题之前根本不知道梅森素数。。。好像如果f(n)=sigma(d|n,d)=2^k,n一定是不重复的梅森素数之积,且k=梅森指数之和。。。
具体看这篇吧:http://blog.csdn.net/acm_cxlove/article/details/7860735
代码:
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 int k,cnt,pp[8]={2,3,5,7,13,17,19,31},sum[256],ans; 6 long long p[8]={3,7,31,127,8191,131071,524287,2147483647}; 7 bool v[256]; 8 int calc(int x){ 9 int y=0; 10 for(int i=0;i<8;i++) 11 if(x%p[i]==0){ 12 x/=p[i];y=y+(1<<i); 13 } 14 if(x!=1)return -1; 15 return y; 16 } 17 int main(){ 18 //freopen("data.in","r",stdin); 19 //freopen("data.out","w",stdout); 20 for(int i=0;i<256;i++) 21 for(int j=0;j<8;j++) 22 if(i&(1<<j))sum[i]+=pp[j]; 23 while(~scanf("%d",&k)){ 24 memset(v,0,sizeof(v));v[0]=1; 25 for(int i=1;i<=k;i++){ 26 int x;scanf("%d",&x); 27 x=calc(x); 28 if(x==-1)continue; 29 for(int j=255;j;j--) 30 if((j&x)==x&&v[j^x])v[j]=1; 31 } 32 ans=0; 33 for(int i=0;i<256;i++) 34 if(v[i]&&sum[i]>ans)ans=sum[i]; 35 if(ans)printf("%d ",ans); 36 else printf("NO "); 37 } 38 return 0; 39 }