UVa 11752 The Super Powers (数学)

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=28 52

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.

用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;
}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索include
, super
, power
, and
, The
合数
superpowers、super powers、草图大师8.0.11752、子宫电击棒 hotpowers、acgpoweracgpowers,以便于您获取更多的相关知识。

时间: 2024-08-03 06:21:47

UVa 11752 The Super Powers (数学)的相关文章

UVa 701 The Archeologists&#039; Dilemma: 数学及枚举

701 - The Archeologists' Dilemma Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=642 An archeologist seeking proof of the presence of extraterrestrials i

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.

UVa 10624:Super Number, Rujia Liu的神题

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=112&page=show_problem&problem=1565 原题: Don't you think 162456723 very special? Look at the picture below if you are unable to find its speciality. (a | b mea

UVa 143 Orchard Trees:数学&amp;amp;计算几何&amp;amp;枚举

143 - Orchard Trees Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=79 An Orchardist has planted an orchard in a rectangle with trees uniformly spaced in both directions.

UVa 10916 Factstone Benchmark:数学及阶乘的处理技巧

10916 - Factstone Benchmark Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1857 Amtel has announced that it will release a 128-bit computer chip by 2010,

UVa 10018 Reverse and Add (数学&amp;amp;利克瑞尔数)

10018 - Reverse and AddTime limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=959 The Problem The "reverse and add" method is simple: choose a number,

UVa 10162 Last Digit:数学规律

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1103 1. 先看单个数的规律: 0^n%10: 0 1^n%10: 1 2^n%10: 2,4,8,6 3^n%10: 3,9,7,1 4^n%10: 4,6 5^n%10: 5 6^n%10: 6 7^n%10: 7,9,3,1 8^n%10: 8,4,2,

DT科技评论第17期:下一代计算机架构登场!

DT科技评论 Data Technology Review 第 17 期           人民网研究院,阿里云研究中心 本期目录 AWS re:Invent2016大会召开 下一代计算机架构登场! 焦灼的云战争:阿里和亚马逊如何赢? 微软Azure出现致命漏洞 谷歌用海风给数据中心供能散热 谷歌新目标--让计算机实现自我编程 IBM识别癌变细胞技术取得重大突破 英特尔成立自动驾驶事业部 智能识别进入金融领域应用阶段 亚马逊用机器人备战销售旺季 人工智能提示:本周热点科技事件,是阿里云"ET&

UVa 10013 Super long sums:简单高精度

10013 - Super long sums Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=954 The Problem The creators of a new programming language D++ have found out that