Vivian's Problem
来源:互联网 发布:爸爸去哪儿 马蓉 知乎 编辑:程序博客网 时间:2024/05/16 18:12
Vivian's Problem
Time Limit:1000MS Memory Limit:30000K
Total Submit:299 Accepted:89
Description
The desire to explore the unknown has been a driving force in human history since the dawn of time. From the earliest documented accounts, ancient civilizations had explored the earth by sailing around. Early adventurers were motivated by religious beliefs, the desire conquest, the need to establish trade routes, and hunger for gold.
You never know what will happen before the exploration. Neither does Bruce Lee. Someday, Mr.Lee entered a desolate tropical rainforest. And after several days' exploring, he came in front of a cave with something blinking in it. A beautiful girl named Vivian came out just before he tried to go into the cave. And Vivian told Mr. Lee that he must answer some questions before he entered the cave. As the best friend of Mr. Lee, you should help him to work it out.
You will get k positive integers p1, p2 ... pi ... pk (1 <= i <= k) from Vivian. From these numbers, you can calculate N, N=Π1<=i<=kpiei (0 <= ei <= 10, Σ1<=i<=kei>=1, 1 <= i <= k); you may decide the integers eis as you wish. From one N, you can calculate corresponding M, which equals to the sum of all divisors of N. Now, you should tell Vivian whether or not there is an M which is the power of 2 (1,2, 4, 8, and 16 … so on). If there's no N can make M equal to the power of 2, tell Vivian "NO". If M equals to some 2x, then show her the exponent (x). And if there are several x, only show her the largest one.
Input
Input contains several testcases. For each testcase, the first line contains only one integer k (0 < k <= 100), representing the number of positive integers. Then there are k positive integers p1, p2 ... pi ... pk (1 < pi < 231, 1 <= i <= k) in the second line, representing the given numbers.
Input is terminated by end of file.
Output
For each testcase, you should output your result in a single line. If you can find N from the given numbers, output the largest exponent. Otherwise, output "NO". Extra spaces are not allowed.
Sample Input
Sample Output
class Test
...{
static int deg[]=...{1,2,4,8,16,32,64,128,256};
static int expolent[]=...{2,3,5,7,13,17,19,31};
static int mersennePrime[]=...{(1<<2)-1,(1<<3)-1,(1<<5)-1,(1<<7)-1,(1<<13)-1,(1<<17)-1,(1<<19)-1,(1<<31)-1};
static int mark[];
public static void main(String[] args)throws Exception
...{
BufferedReader bf=new BufferedReader(new FileReader("vivian.in"));
int c[]=new int[256];
for(int i=0;i<256;i++)//init
...{
c[i]=0;
for(int j=0;j<8;j++)
if((i°[j])>0)
c[i]=c[i]+expolent[j];
}
while(bf.ready())
...{
int n=Integer.parseInt(bf.readLine());
String tmp[]=bf.readLine().split(" ");
mark=new int[256];
mark[0]=1;
for(int i=0;i<tmp.length;i++)
...{
int mask=0;
int p=Integer.parseInt(tmp[i]);
int j;
for(j=0;j<8;j++)
...{
int cout=0;
while(p%mersennePrime[j]==0)//分解Pi
...{
p/=mersennePrime[j];
cout++;
}
if(cout==1)mask|=deg[j];
else if(cout>=2)...{mask=-1;break;}
}
if(p>1)mask=-1;
if(mask<=0)continue;
for(j=0;j<256;j++)
if((j&mask)==mask&&mark[j^mask]==1)//状态转移方程
mark[j]=1;
}
int ans=0;
for(int i=0;i<256;i++)
if(mark[i]==1&&ans<c[i])ans=c[i];
if(ans==0)System.out.println("NO");
else System.out.println(ans);
}
}
}
NO2
1232 3 4
- Vivian's Problem
- poj 1777 Vivian's Problem
- UVA - 1323 Vivian's Problem
- Vivian's Problem 梅森素数
- POJ 1777 Vivian's Problem(梅森素数)
- uva 1323 - Vivian's Problem(梅森素数)
- 【数论】poj1777 Vivian's Problem(梅森素数)
- Problem S
- Problem-S
- Problem S
- Eva's Problem
- PKU_ACM_1658_Eva's Problem
- Little Boy's Problem
- pku1899Farmer Bill's Problem
- Shoemaker's Problem
- iew's problem
- poj1658 Eva's Problem!
- Painter's Problem POJ1681
- 营销2.0时代
- 我也有博客了
- 终于决定总结自己的图像处理库
- 在main函数前后执行代码的方法
- 一步一步学Repast 第二章(把界面显示出来)
- Vivian's Problem
- 与恋爱无缘
- SQL的同步
- 传递同一sessionID
- 转贴一篇如何成为Java高手
- MS VC++ 6.0 fatal error C1010的解决方法
- 怎样将.Net程序部署到没有安装.Net Framwork的机器上?
- 整数映射和类型映射
- 安装ASP.NET AJAX