TOJ1502Find All M^N Please

来源:互联网 发布:node sass windows 编辑:程序博客网 时间:2024/06/08 13:42

Find All M^N Please 分享至QQ空间 去爱问答提问或回答

Time Limit(Common/Java):1000MS/10000MS     Memory Limit:65536KByte
Total Submit: 37            Accepted: 15

Description

Recently, Joey has special interest in the positive numbers that could be represented as M ^ N (M to the power N), where M and Nare 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.

Input

 

Output

Output all M^N numbers as shown in the output samples.

Sample Input

Sample Output

48916252732|| <-- a lot more numbers|102410891156122512961331|||

#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define MAX 50000using namespace std;double INF = 2147483648.0;int v[MAX];int main(){    int i, j, k = 0;    memset(v, 0, sizeof(v));    for (i = 2; i <= (int)sqrt(INF); i++ ) {        for ( j = 2; j <= (int)(log(INF) / log(i)); j++ ) {            v[k++] = (int)(pow(1.0*i, 1.0*j) + 0.5);            //v[k++] = (int)(pow(1.0*i, 1.0*j) );!!!精度.        }    }    sort(v, v+k);    for ( i = 1; i < k; i++ ) {        if ( v[i] != v[i-1] ) {            printf("%d\n", v[i]);        }    }    return 0;}

原创粉丝点击