ZOJ 2952 Find All M^N Please(数学啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1951

Recently, Joey has special interest in the positive numbers that could be represented as M ^ N (M to the power N), where M and N are
both positive integers greater than or equal to 2. For example, 4, 8, 9 and 16 are first four such numbers, as 4 = 2 ^ 2, 8 = 2 ^ 3, 9 = 3 ^ 2, 16 = 2 ^ 4. You are planning to give Joey a surprise by giving him all such numbers less than 2 ^ 31 (2147483648).
List them in ascending order, one per line.

Sample Output

4
8
9
16
25
27
32
|
| <-- a lot more numbers
|
1024
1089
1156
1225
1296
1331
|
|
|

Author: SHEN, Guanghao

Source: Zhejiang University Local Contest 2008

代码如下:

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#define MAX 2147483648
using namespace std;
long long a[400000];
int main()
{
    int i,j,k,x = 0;
    long long s;
    for(i = 2 ; i <= sqrt(MAX) ; i++ )
    {
        for(j = 2; j <= 31 ; j++ )
        {
            s = 1;
            for( k = 1 ; k <= j ; k++)
                s*=i;
            if( s >= MAX )
                break;
            else
                a[x++] = s;
        }
    }
    sort(a,a+x);
    printf("%d\n",a[0]);
    for(i = 1 ; i < x ; i++)
    {
        if(a[i]!=a[i-1])
            printf("%lld\n",a[i]);
    }
    return 0;
}

时间: 2024-10-26 07:15:38

ZOJ 2952 Find All M^N Please(数学啊 )的相关文章

HDU 4791 &amp;amp; ZOJ 3726 Alice&amp;#39;s Print Service (数学 打表)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072 Problem Description Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her pr

ZOJ 3829 Known Notation(字符串处理 数学 牡丹江现场赛)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5383 Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an ex

POJ 3652 &amp; ZOJ 2934 &amp; HDU 2721 Persistent Bits(数学 进制)

题目链接: PKU:http://poj.org/problem?id=3652 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1933 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2721 Description WhatNext Software creates sequence generators that they hope will produce fair

HDU 4791 &amp; ZOJ 3726 Alice&#39;s Print Service (数学 打表)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=4791 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5072 Problem Description Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using her pr

[数学+dfs] ZOJ 3753 Simple Equation

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5176 Simple Equation Time Limit: 2 Seconds      Memory Limit: 65536 KB There are many Equations. Some are difficult to solve, for example: an xn + an-1 xn-1 + .. + a0 = 0. In this probl

ZOJ 3407 Doraemon&#39;s Cake Machine [数学]

题意: 最多有2000组测试样例,每组样例代表n,m; n代表要把蛋糕平分的份数,m代表必须进行多少次操作. 一共有三种操作 1.竖切   经过蛋糕圆心,将蛋糕整个向下切. 2.横切   平行于蛋糕平面进行平切. 3.复制某块小蛋糕    这种操作只能在1和2所有操作都进行完才能进行. 求: 最少进行多少次复制操作可以将蛋糕分为一样的恰好n种.注意需要用恰好m次操作. 如果没有可行解输出-1. 思路: 假设进行三种操作的数目分别是xyz.然后连立两个式子把z消掉,get 2x(y+1)-(x+y

HDU 1988 &amp; ZOJ 2991 Flipping Burned Pancakes(数学啊+模拟)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1988 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1990 Problem Description The cook at the Frobbozz Magic Pancake House sometimes falls asleep on the job while cooking pancakes. As

HDU 1990 &amp; ZOJ 2992 Monkey Vines(数学啊)

题目链接: HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1990 ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1991 Problem Description Deep in the Amazon jungle, exceptionally tall trees grow that support a rich biosphere of figs and junipe

ZOJ 3230 Solving the Problems(数学 优先队列啊)

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3230 Programming is fun, Aaron is addicted to it. In order to improve his programming skill, he decides to solve one programming problem per day. As you know, different problems have d