uva 11752 - The Super Powers

这个题   任意一个数,他的幂只要不是质数则可以分解成两个数的乘   判断有没有溺出  i×i  则用最大的那个数 Max/i < i 吗 

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<stdio.h>
 6 #include<set>
 7 using namespace std;
 8 typedef  unsigned long long ll;
 9 const ll Max = 0xffffffffffffffffLL;//18446744073709551615;
10 set<ll>s;
11 bool work( int num ){
12     for( int i = 2; i <= sqrt(num); i++ )
13     if( !(num%i) ) return false;
14     return true;
15 }
16 int main( )
17 {
18     //freopen("out1.txt","w",stdout);
19     s.clear(); s.insert(1); set<ll>::iterator it;
20     for( ll i = 2; i <= (1<<22); i++ )
21     {
22         ll ans = i*i;  int num = 2;
23         while( 1 ){
24             if( Max/ans < i )break;
25             ans = ans*(i); num++;
26             if( !work(num) )s.insert(ans);
27         }
28     }
29     for( it = s.begin(); it != s.end(); it++ )
30     printf("%llu\n",*it);
31     return 0;
32 }
33   
View Code

 

posted on 2013-09-30 19:51  浪舟  阅读(342)  评论(0编辑  收藏  举报

导航