Q412: Pi

//Q412 Pi
//Accepted 2008-04-20 11:18:00
#include <iostream>
#include <iomanip>
#include <cmath>
#include <stdio.h>

using namespace std;

int gcd(int, int);

int p[32768];
int main(void)
{
int t = 0, n[50];
double pi, tt, bp = 0;

while(cin >> t)
{
bp = 0;
if (t == 0)
exit(0);
for(int i = 0; i < t; i++)
cin >> n[i];
for(int i = 2; i <= t; i++)
for(int j = 1; j <= i - 1; j++)
if (n[j - 1] > n[i - 1])
{
if (gcd(n[j - 1], n[i - 1]) == 1)
bp++;
}
else
{
if (gcd(n[i - 1], n[j - 1]) == 1)
bp++;
}

tt = t * (t - 1) / 2;
if (bp == 0)
cout << "No estimate for this data set." << endl;
else
{
pi = sqrt(tt * 6 / bp);
cout << setprecision(6) << fixed << pi << endl;
}
}
return 0;
}

int gcd(int a, int b)
{
return (b == 0)? a: gcd(b, a % b);
}

留言

這個網誌中的熱門文章

成功安裝Vista & Ubuntu Linux 8.04 LTS 雙系統!!!

駕訓班~XD