Posted on 2008-12-10 23:48
Hero 阅读(119)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 // 1352 C++ Accepted 0.031 121 KB URAL
2
3 //打表的题目
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 const int size = 40 ;
10
11 int data[size] ;
12
13 bool fisprime( int x )
14 {
15 if( 2 == x ) return true ;
16 if( 0 == (x&1) ) return false ;
17 for( int i=3; i*i<=x; i+=2 )
18 if( 0 == x%i ) return false ;
19
20 return true ;
21 }
22
23 int main()
24 {
25 data[1] = 2 ; data[2] = 3 ;
26 data[8] = 31 ; data[9] = 61;
27 data[10] = 89; data[11] = 107;
28 data[12] = 127 ; data[13] = 521;
29 data[14] = 607; data[15] = 1279;
30 data[16] = 2203; data[17] = 2281;
31 data[18] = 3217 ; data[19] = 4253 ;
32 data[20] = 4423 ; data[21] = 9689 ;
33 data[22] = 9941 ; data[23] = 11213;
34 data[24] = 19937 ; data[25] = 21701;
35 data[26] = 23209; data[27] = 44497 ;
36 data[28] = 86243 ; data[29] = 110503 ;
37 data[30] = 132049 ; data[31] = 216091 ;
38 data[32] = 756839 ; data[33] = 859433 ;
39 data[34] = 1257787 ; data[35] = 1398269 ;
40 data[36] = 2976221 ; data[37] = 3021377 ;
41 data[38] = 6972593 ;
42
43 int cnt = 2 ;
44 unsigned pow2 = 8 ; int pow = 2 ;
45 unsigned curval ;
46 for( int i=4; i<=30; i++ )
47 {
48 curval = (pow2 = pow2<<1) - 1 ; pow++ ;
49 if( fisprime(curval) )
50 {
51 data[++cnt] = i ;
52 }
53 if( cnt >= 7 ) break ;
54 }
55
56 int innum ; int inn ;
57 while( scanf( "%d", &innum ) != EOF )
58 {
59 while( innum -- )
60 {
61 scanf( "%d", &inn ) ;
62 printf( "%d\n", data[inn] ) ;
63 }
64 }
65
66 return 0 ;
67 }