UVA11752 The Super Powers

 1 /*
 2  UVA11752 The Super Powers 
 3  https://vjudge.net/contest/153365#problem/Y
 4  数论
 5  注意a^n=b要用除法求,并且求得的n比实际大1
 6  */
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <cstring>
10 #include <cmath>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <iostream>
15 //#define test
16 using namespace std;
17 const int Nmax=1005;
18 set<unsigned long long> ans;
19 int is_prime[Nmax];
20 int cnt;
21 void get()
22 {
23     for(int i=2;i<=64;i++)
24         is_prime[i]=1;
25     for(int i=2;i<=64;i++)
26         if(is_prime[i])
27             for(int j=2;j*i<=64;j++)
28                 is_prime[i*j]=0;
29 }
30 
31 int main()
32 {
33     #ifdef test
34     #endif
35     ans.insert(1LL);
36     get();
37     //for(int i=1;i<=cnt;i++)
38         //printf("%d ",num[i]);
39     //printf("\n");
40     //printf("%lld\n",qpow(65536LL,4));
41     unsigned long long n=(1LL<<64)-1LL;
42     //printf("n:%llu\n",n);
43     //return 0;
44     for(unsigned long long i=2LL;;i++)
45     {
46         unsigned long long cnt=-1,x=n;//算出最大的次数,注意最大次数要-1
47         while(x>0)
48         {
49             x/=i;
50             cnt++;
51         }
52         if(cnt<4)
53             break;
54         unsigned long long a=i;
55         //不能这么乘,会超unsigned long long
56         //unsigned long long tmp=i*i*i*i;//
57         ////printf("%lld\n",tmp);
58         //if(tmp>n)
59             //break;
60         for(unsigned long long j=2;j<=cnt;j++)
61         {
62             a*=i;
63             //printf("a:%lld\n",a);
64             //if(a<=0LL)
65                 //break;
66             //if(a>n)
67             //{
68                 //printf("YES\n");
69                 //return 0;
70                 //break;
71             //}
72             if(!is_prime[j])
73                 ans.insert(a);
74         }
75     }
76     for(set<unsigned long long>::iterator i=ans.begin();i!=ans.end();i++)
77         //cout<<*i<<endl;
78     //unsigned long long 要用llu输出,否则会丢数据
79         printf("%llu\n",*i);
80     return 0;
81 }

 

posted @ 2017-03-29 20:28  BBBob  阅读(293)  评论(0编辑  收藏  举报