#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<string> #include<math.h> #include<cctype> #define ll long long #define REP(i,a,b) for(int (i)=(a);(i)<=(b);(i)++) #define REPP(i,a,b,t) for(int (i)=(a);(i)<=(b);(i)+=(t)) #define PII pair<int,int> #define MP make_pair #define PB push_back #define RI(x) scanf("%d",&(x)) #define RLL(x) scanf("%lld",&(x)) #define RI64(x) scanf("%I64d",&(x)) #define DRI(x) int x;scanf("%d",&(x)) #define DRLL(x) ll x;scanf("%lld",&(x)) #define DRI64(x) llx;scanf("%I64d",&(x)) #define MS0(a) memset((a),0,sizeof((a))) #define MS1(a) memset((a),0,sizeof((a))) #define MS(a,b) memset((a),(b),sizeof((a))) using namespace std; typedef unsigned long long ull; const int maxn=1000100; const ull INF=(1LL<<64)-1; const double EPS=0.0000000001; const double Pi=acos(-1.0); bool isprime[maxn]; vector<int> np; set<ull> vis; ll qpow(ull n,ull k) { ull res=1; while(k){ if(k&1) res*=n; n*=n; k>>=1; } return res; } void getNotPrime() { MS(isprime,1); REP(i,2,maxn-1){ if(!isprime[i]) continue; REPP(j,i*2,maxn-1,i) isprime[j]=0; } REP(i,2,64){ if(!isprime[i]) np.PB(i); } } int main() { getNotPrime(); puts("1"); REP(i,2,(1<<16)){ REP(j,0,(int)np.size()-1){ if(np[j]*log10(i*1.0)>=64*log10(2.0)) break; ull x=qpow(i,np[j]); //cout<<i<<" "<<np[j]<<endl;getchar(); if(vis.find(x)==vis.end()){ vis.insert(x); } } } for(set<ull>::iterator it=vis.begin();it!=vis.end();it++) printf("%llu\n",*it); return 0; }
原文:http://www.cnblogs.com/--560/p/4572803.html