本文共 903 字,大约阅读时间需要 3 分钟。
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
48916252732|| <-- a lot more numbers|102410891156122512961331|||
因为底数最大不超过1e5,所以只需要暴力枚举,用个vector保存结果,排个序输出即可。
#include#include #include #include #include using namespace std;typedef long long ll;const int maxn=1e5+5;int m,n;int vis[maxn];vector v;int main(){ memset (vis,0,sizeof(vis)); for (int i=2;i =2147483648) break; if(!vis[i]) { for (ll j=i*i;j<2147483648;j*=i) { if(j
转载地址:http://nkoen.baihongyu.com/