码迷,mamicode.com
首页 > 其他好文 > 详细

The Super Powers

时间:2014-07-22 23:09:34      阅读:554      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   

Time Limit: 1000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

[]   [Go Back]   [Status]  

Description

 

A

The Super Powers

 

 

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 = 82 and 64 =  43. You have to write a program that lists all super powers within 1 and 264 -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. 

Sample Input                              

Partial Judge Output

No input for this problem   

 

1

16
64

81
256

512
.
.
.

 

 

mamicode.com,码迷
 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<set>
 4 #include<math.h>
 5 #include<iostream>
 6 #include<algorithm>
 7 using namespace std;
 8 #define  ll unsigned long long
 9 int a[100]= {0},nu;
10 void init()
11 {
12     int i,j;
13     nu=0;
14     for(i=2; i<100; i++)
15     {
16         if(!a[i])
17         {
18             j=i*i;
19             while(j<100)
20             {
21                 a[j]=1;
22                 j+=i;
23             }
24         }
25     }
26     j=0;
27     for(i=4; i<65; i++)if(a[i])a[j++]=i;
28     //for(i=0; i<j; i++)cout<<a[i]<<endl;
29     nu=j;
30 }
31 ll powLL(ll x, ll y)
32 {
33     ll ans=1;
34     while(y)
35     {
36         if(y&1)
37         ans*=x;
38         x*=x;
39         y>>=1;
40     }
41     return ans;
42 }
43 int main()
44 {
45     init();
46     int i,j,size;
47     ll  maxa=~0ULL,n;
48     //cout<<maxa<<endl;
49     set<ll>aa;
50     aa.clear();
51     aa.insert(1);
52     for(i=2;;i++)
53     {
54         size=0;
55         n=maxa;
56         while(n>=i) n/=i,size++;
57         if(size<4) break;
58         for(j=0;j<nu;j++)
59         {
60             if(a[j]<=size)
61             aa.insert(powLL(i, a[j]));
62             else break;
63         }
64     }
65     for(set<ll>::iterator it=aa.begin();it!=aa.end();it++)
66     printf("%llu\n",*it);
67 }
View Code

 

The Super Powers,码迷,mamicode.com

The Super Powers

标签:des   style   blog   http   color   os   

原文地址:http://www.cnblogs.com/ERKE/p/3700280.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!