#include<cstdio> #include<string> #include<cstring> #include<iostream> #include<cmath> using namespace std; int divisor(int n, int m) { int c; while(n%m!=0) { c=n%m; n=m; m=c; } return m; } int main() { int n; while(scanf("%d",&n)==1&&n!=0) { int a[n+1],i,j,k,l=0,m=0,npairs=0; for(i=0;i<n;i++)scanf("%d",&a[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { l=divisor(a[i],a[j]); npairs++; if(l==1) { m++; } } } if(m==0)printf("No estimate for this data set.\n"); else { double expected_pi = sqrt(6*npairs/(double)m); printf("%lf\n",expected_pi); } } return 0; }
Sunday, August 17, 2014
uva : 412 - Pi
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment