Advertisement
immuntasir

412

Mar 6th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cmath>
  3. int gcd(int a,int b){
  4.     while(b) b ^= a ^= b ^= a %= b;
  5.     return a;
  6. }
  7. int numbers[50];
  8. int main() {
  9.     int num,i,cnt,j,k,pairs;
  10.     while (scanf("%d", &num)==1) {
  11.         if (num==0) return 0;
  12.         for (i=0;i<num;i++) scanf("%d", &numbers[i]);
  13.         cnt=0;
  14.         pairs=num*(num-1)/2;
  15.         for (i=0;i<num;i++) {
  16.             for (j=i+1;j<num;j++) {
  17.                 if (gcd(numbers[i],numbers[j])==1) cnt++;
  18.             }
  19.         }
  20.  
  21.         if (cnt>0) {
  22.             double ans = sqrt((6*pairs*1.00)/cnt);
  23.             printf("%.6lf\n",ans);
  24.         }
  25.         else printf("No estimate for this data set.\n");
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement