您的位置:首页 > 其它

uva 11752 The Super Powers

2016-08-11 14:02 351 查看
原题:

We all know the Super Powers of this world and how they manage to get advantages in political warfare

or even in other sectors. But this is not a political platform and so we will talk about a different kind

of super powers — “The Super Power Numbers”. A positive number is said to be super power when it

is the power of at least two different positive integers. For example 64 is a super power as 64 = 8 2 and

64 = 4 3 . You have to write a program that lists all super powers within 1 and 2 64 − 1 (inclusive).

Input

This program has no input.

Output

Print all the Super Power Numbers within 1 and 2 64 − 1. Each line contains a single super power

number and the numbers are printed in ascending order.

Note: Remember that there are no input for this problem. The sample output is only a partial solution.

Sample Input

Sample Output

1

16

64

81

256

512

.

.

.

中文:

找出所有1到2^64-1的范围当中的一个数,这个数可以表示为a^x和b^y。没有输入

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
int p[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61};
int vis[70];
const ull maxn=(2<<64)-1;
set<ull> ans;

int main()
{
ios::sync_with_stdio(false);
ans.insert(1);
for(int i=0;i<18;i++)
vis[p[i]]=1;
for(ull i=2;;i++)
{
ull tmp=maxn;
int ind=-1;
while(tmp)
{
tmp/=i;
ind++;
}
if(ind<4)
break;
tmp=i;
for(ull j=2;j<=ind;j++)
{
tmp*=i;
if(!vis[j])
ans.insert(tmp);
}
}
for(auto x:ans)
cout<<x<<endl;

return 0;
}


解答:

只要找出一个数,让他的次幂数是一个合数即可。但是程序没写出来,看别人题解明白了。每次都用2^64-1不断去除一个数,除了多少次,就是这个数的次幂数。放入set中去重即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: