The Super Powers

本文详细介绍了如何通过编程列出1到2^64-1之间的所有超能力数,即能被至少两个不同的正整数幂次方表示的数字。通过数学算法和代码实现,逐步揭示了这一独特数字集的生成过程。
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
.
.
.

 

 

 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

 

转载于:https://www.cnblogs.com/ERKE/p/3700280.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值