Posted on 2009-06-02 16:19
Hero 閱讀(87)
評論(0) 編輯 收藏 引用 所屬分類:
代碼如詩--ACM
1 //1214 Accepted 15 180 1982 C++
2
3 //分解質(zhì)因數(shù)的時(shí)候別忘了最后剩余項(xiàng)
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 ;//錯(cuò)在漏掉了這句話,比如說34=2*17,可能會漏掉17
37
38 int out = inn / x ;
39
40 printf( "%d\n", out+1 ) ;
41 }
42 }
43 return 0 ;
44 }
45