1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | #include <iostream> #include <cstdio> #include <cmath> #define LEN 52 using namespace std; unsigned int gcd( unsigned int , unsigned int ); /* 這論壇不錯阿 大家都不用@@ http://online-judge.uva.es/board/viewtopic.php?f=5&t=8221&p=102632&hilit=412&sid=a479f43c6e4962712ced715f3c475cd9#p102632 我的UVa進不去 網路太慢 所以用ZJ測了 http://zerojudge.tw/RealtimeStatus?account=x000032001&status=AC 有問題再看看吧? */ int main() { int n; //設定要輸入幾組數,最多50 while( cin >> n && n ) { unsigned int s[LEN] = {}; for( int i = 0 ; i < n ; i++) cin >> s[i]; //將所輸入的數丟進 s[i] 中 unsigned int k = 0; //算所輸入的數中,互質的個數 for ( int i = 0 ; i < n ; ++i ) for ( int j = i + 1 ; j < n ; ++j ) { if ( gcd( s[ i ], s[ j ] ) == 1 ) //互質的話,k+1 k++; } if ( k == 0 ) cout << "No estimate for this data set." << endl; else { double pi = sqrt( (n-1)*(double)n*3/(double)k ); printf("%.6f\n",pi); } } return 0; } unsigned int gcd( unsigned int a , unsigned int b )//求最小公因數 { while(1) { a = a%b; if(a==0)return b; b = b%a; if(b==0)return a; } } |
Direct link: https://paste.plurk.com/show/296284