题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2052
2052: Pku1777 Vivian
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 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
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int k,cnt,pp[]={,,,,,,,},sum[],ans;
long long p[]={,,,,,,,};
bool v[];
int calc(int x){
int y=;
for(int i=;i<;i++)
if(x%p[i]==){
x/=p[i];y=y+(<<i);
}
if(x!=)return -;
return y;
}
int main(){
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
for(int i=;i<;i++)
for(int j=;j<;j++)
if(i&(<<j))sum[i]+=pp[j];
while(~scanf("%d",&k)){
memset(v,,sizeof(v));v[]=;
for(int i=;i<=k;i++){
int x;scanf("%d",&x);
x=calc(x);
if(x==-)continue;
for(int j=;j;j--)
if((j&x)==x&&v[j^x])v[j]=;
}
ans=;
for(int i=;i<;i++)
if(v[i]&&sum[i]>ans)ans=sum[i];
if(ans)printf("%d\n",ans);
else printf("NO\n");
}
return ;
}