简单的数论题:主要的注意点是计算幂的时候尽量少用pow,精度损失太大。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
#include <fstream>
using namespace std;
const int maxn = 100 + 10;
bool vis[maxn];
map<unsigned long long,bool> mm;
vector<unsigned long long >ans;
void sieve(int n){
int m = (int)(sqrt(n+0.5));
memset(vis,0,sizeof(vis));
for(int i = 2; i <= m; i++) if(!vis[i]){
for(int j = i*i; j <= n; j += i){
vis[j] = 1;
}
}
}
int main(){
sieve(70);
mm.clear();
ans.push_back(1);
for(unsigned long long i = 2; i < 65536; i++){
unsigned long long tmp = i;
for(unsigned long long j = 2; j <= ceil(64.0*log(2)/log(i))-1; j++){
tmp *= i;
if(!vis[j]){
continue;
}
//精度要注意啊unsigned long long tmp = (unsigned long long)(pow(i*1.0,j*1.0));
if(!mm[tmp]){
ans.push_back(tmp);
if(tmp == 0){
}
mm[tmp] = 1;
}
}
}
sort(ans.begin(),ans.end());
for(int i = 0; i < ans.size();i++){
cout<<ans[i]<<endl;
}
return 0;
}