Posted on 2009-06-02 16:19
Hero 阅读(83)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //1214 Accepted 15 180 1982 C++
2
3 //分解质因数的时候别忘了最后剩余项
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <math.h>
9
10 int intest ;
11 int inn ;
12
13 int main()
14 {
15 //freopen( "in.txt", "r", stdin ) ;
16 //freopen( "out.txt", "w", stdout ) ;
17
18 while( scanf( "%d", &intest ) != EOF )
19 {
20 while( intest-- )
21 {
22 scanf( "%d", &inn ) ;
23 int maxi = (int)(sqrt(inn*1.0)+10) ;
24 int x = 1 ; int tinn = inn ;
25 bool isprime = true ;
26 for( int i=2; i<=maxi; i++ )
27 {
28 if( 0 == tinn % i )
29 {
30 x = x * i ;
31 isprime = false ;
32 while( 0 == tinn%i ) tinn = tinn / i ;
33 }
34 }
35
36 x = x * tinn ;//错在漏掉了这句话,比如说34=2*17,可能会漏掉17
37
38 int out = inn / x ;
39
40 printf( "%d\n", out+1 ) ;
41 }
42 }
43 return 0 ;
44 }
45