uva 11752 -The Super Powers (数论)
来源:互联网 发布:数据出售 编辑:程序博客网 时间:2024/05/16 15:38
We all know the Super Powers of this world and how they manage to get advantages in political warfareor even in other sectors. But this is not a political platform and so we will talk about a different kindof super powers — "The Super Power Numbers". A positive number is said to be super power when itis the power of at least two different positive integers. For example 64 is a super power as 64 = 82 and64 = 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
No input for this problem
Partial Judge Output
1
16
64
81
256
512
.
.
.
题目大意:超级幂(要求要打到1-2^64 -1的数,该数是两个或以上的正整数的幂次方),没有输入,只有输出打表!
思路:首先想到了素数的合数次方,最小的合数(也就是幂)是4,那么最大的底数(也就是要打的素数表的最大值是2^16,也就是1<<16,开到65536的数组足够),按照这种思路,却T了很多次,最后问学长,才知道打的时候没有判断,到最后打的太多反而T了,加判断的方法是判断指数要小于ceil(64.0/log(i)*log(2)),按说到此应该Ac了,可是又wa了一次,原来一开始推错了,应该打所有数的合数次方,最后去重即可,表示用vector打素数的合数次方打的好伤心,正解用set/map存,去重和排序一体。
code:
# include<iostream>
# include<cstdio>
# include<cstring>
# include<set>
# include<cmath>
# include<algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=65546;
set<ull>s;
set<ull>::iterator it;
bool vis[N];
ull mi (int n,int m) //二分幂
{
if (m==0) return 1;
if (m%2==0)
return mi(n,m/2)*mi(n,m/2);
else
return n*mi(n,m/2)*mi(n,m/2);
}
void get_prim() //打素数表
{
int i,j;
memset(vis,true,sizeof(vis));
vis[0]=vis[1]=false;
for(i=2;i<N;++i)
{
if(!vis[i]) continue;
for(j=i+i;j<N;j+=i)
vis[j]=false;
}
}
int main()
{
int i,j;
s.insert(1);
get_prim();
for(i=2;i<=65536-1;++i)
{
double t=ceil(64.0/log(i)*log(2))-1; //关键:加指数判断
for(j=4;j<=t;++j)
{
if(vis[j]) continue;
s.insert(mi(i,j));
}
}
for(it=s.begin();it!=s.end();++it)
printf("%llu\n",*it);
return 0;
}
- UVA 11752 - The Super Powers (数论)
- UVa 11752 - The Super Powers (数论)
- uva 11752 -The Super Powers (数论)
- uva 11752 - The Super Powers(数论+枚举技巧)
- 【数论 && 找规律】UVA 11752 The Super Powers
- UVA - 11752 The Super Powers
- UVA 11752-The Super Powers
- Uva 11752 The Super Powers
- UVA 11752 The Super Powers
- uva 11752The Super Powers
- UVA 11752 The Super Powers
- uva 11752 The Super Powers
- UVA 11752 The Super Powers
- The Super Powers UVA
- The Super Powers UVA
- The Super Powers UVA
- UVa 11752 The Super Powers (数学)
- UVa 11752 The Super Powers(数学)
- 第一次训练赛的相关总结和教训!
- uva11029 - Leading and Trailing
- 自己习惯的Eclipse中设置注释模板
- 博客同步测试
- 关于数字签名
- uva 11752 -The Super Powers (数论)
- 使用IronPython给.Net程序加点料
- intel_rapl: no valid rapl domains found in package 0 virtualbox ubuntu
- 如何让浏览器正确识别网页编码
- Java String.startsWith()
- HDU——2186 悼念512汶川大地震遇难同胞——一定要记住我爱你
- 程序运行遇到adb问题
- C语言 求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,例如:2+22+222+2222+22222
- Mysql数据类型简介