UVa 11752 The Super Powers (数学)

262 篇文章 0 订阅
100 篇文章 0 订阅

11752 - The Super Powers

Time limit: 1.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=2852

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
.
.
.


用set实现,也可以用数组和sort&unique实现(更快)


完整代码:

/*0.036s*/

#include<cstdio>
#include<cmath>
#include<set>
#define LL unsigned long long
using namespace std;
const int index[100] =
{
	4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26,
	27, 28, 30, 32, 33, 34, 35, 36, 38, 39, 40, 42, 44, 45, 46,
	48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 60, 62, 63, 64  /// 多算一个
};///合数表

set<LL> ans;

int main(void)
{
	LL i, maxi = 1 << 16; /// 底数的上限
	int j, maxindex; /// 指数的上限
	LL cur;
	ans.insert(1);
	for (i = 2; i < maxi; i++)
	{
		cur = i * i; /// i用LL类型的原因
		cur *= cur;
		ans.insert(cur);
		maxindex = ceil(64 * log(2) / log(i)) - 1; /// 指数的上限
		for (j = 1; index[j] <= maxindex; ++j)
		{
			cur *= (index[j] - index[j - 1] == 1 ? i : i * i);
			ans.insert(cur);
		}
	}
	for (set<LL>::iterator iter = ans.begin(); iter != ans.end(); ++iter)
		printf("%llu\n", *iter);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值