412 pi.cpp

来自「UVA Online Judge solutions to the proble」· C++ 代码 · 共 50 行

CPP
50
字号
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int gcd(int a,int b)
{
     int x,z;
     if(b==0)
     return a;
     x=a%b;
     z=gcd(b,x);
     return z;
}
int main()
{
    int n,i,j;
    int arr[60];
    float ans;
    while(cin>>n && n!=0)
    {
                 for(i=0;i<n;i++)
                 cin>>arr[i];
                 
                 int deno=n*(n-1)/2;
                 int num=0;
                 for(i=1;i<n;i++)
                 {
                         for(j=0;j<i;j++)
                         {
                                         if(gcd(arr[i],arr[j])==1) 
                                         num++;
                                         else
                                         continue;
                         }
                 }
                 
                
                 if(num!=0)
                 {
                  float mul=(deno*6)/(float)num;
                  ans=sqrt(mul);
                  printf("%.6lf\n",ans);
                  }
                 else
                 cout<<"No estimate for this data set."<<endl;
    }
    system("pause");
}
                  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?