Pi

来源:互联网 发布:淘宝充值网易宝 编辑:程序博客网 时间:2024/04/25 20:34

#include <iostream>

#include <iomanip>

#include <math.h>

using namespace::std;


int cal(int a,int b)

{

if(b==0)

return a;

else 

return cal(b,a%b);

}

int main()

{

int n;

while(cin >> n&&n)

{

int i,j,a[52]={0};

double k,m=0;

for(i=0;i<n;i++)

cin >> a[i];

k=n*(n-1)/2;

for(i=0;i<n;i++)

for(j=i+1;j<n;j++)

if(cal(a[i],a[j])==1)

m++;

if(m==0)

cout << "No estimate for this data set.\n";

else 

printf("%.6f\n",sqrt(6.0*k/m));

}

return 0;

}

/*

 Problem description

 Professor Robert A. J. Matthews of the Applied Mathematics and Computer Science Department at the University of Aston in Birmingham, England has recently described howthe positions of stars across the night skymay be used to deduce a surprisingly accurate value of   . This result followed from the application of certain theorems in number theory.

 Here, we don'thave the night sky, but can use the same theoretical basis to form an estimate for   :

 

 Given any pair of whole numbers chosen from a large, random collection of numbers, the probability that the twonumbers have no common factor other than one (1) is

                        6/(Pi*Pi)

          

 For example, using the small collection of numbers: 2, 3, 4, 5, 6; there are 10 pairs that can be formed: (2,3), (2,4), etc. Six of the 10 pairs: (2,3), (2,5), (3,4), (3,5), (4,5) and (5,6) have no common factor other than one. Using the ratio of the counts as the probability we have:

                        6/(Pi*Pi)约等于6/10

 

                         Pi=3.162

 In this problem, you'll receive a series of data sets. Each data set contains a set of pseudo-random positive integers. For each data set, find the portion of the pairs which may be formed that have nocommon factor other than one (1), and use the method illustrated above to obtain an estimate for   . Report this estimate for each data set.

 

 

 Input

 The input consists of a series of data sets.

 The first line of each data set contains a positive integer value, N, greater than one (1) and less than 50.

 

 There is one positive integer per line for the next N lines that constitute the set for which the pairs are to be examined. These integers are each greater than 0 and less than 32768.

 

 Each integer of the input stream has its first digit as the first character on the input line.

 

 The set size designator, N, will be zero to indicate the end of data. 

 

 

 Output

 A line with a single real value is to be emitted for each input data set encountered. This value is the estimate for   for the data set. An output format like the sample below should be used. Answers must be rounded to six digits after the decimal point.

 For some data sets, it may be impossible to estimate a value for   . This occurs when there are no pairs without common factors. In these cases, emit the single-line message:

 

 No estimate for this data set.

 

 exactly, starting with the first character, "N", as the first character on the line. 

 

 

 Sample Input

 5

 2

 3

 4

 5

 6

 2

 13

 39

 0

 Sample Output

 3.162278

 No estimate for this data set.

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 华为荣耀10边框掉色了怎么办 网购商家打来无货怎么办 客户拍了不发货怎么办 天猫商家欺骗买家怎么办 阿里买家投诉我发空包怎么办 苹果6s电池坏了怎么办 hm买的单鞋脏了怎么办 微店违规屏蔽搜索怎么办 ios微信支付失效怎么办 京东第三方店铺关闭怎么办 京东店铺关门了怎么办 国美退款不到账怎么办 小米小店通过了怎么办 苹果的发票丢了怎么办 苹果7p开不开机怎么办 申请退款了怎么卖家还发货怎么办 买家申请退款卖家不退款怎么办 卖家恶意不退款怎么办 欠条到期了对方不还钱怎么办 冰箱磕了一坑怎么办 办信用卡没有家庭地址的怎么办 钱付了货没收到怎么办 在苏宁易购上买东西地址错了怎么办 手机分期付款银行卡丢了怎么办 华硕笔记本鼠标不动了怎么办 韵达快递不派送怎么办 中通快递不派送怎么办 农业银行信用卡密码输错三次怎么办 农业银行卡多次输错密码怎么办 想把店长弄走怎么办 济南银座卡过期了怎么办 银座购物卡丢失后怎么办 银座的卡丢了怎么办 银行卡换了旧卡怎么办 大理市民卡丢了怎么办 市民卡内的钱怎么办 宝付支付乱扣款怎么办 苏宁任性贷逾期怎么办 第二次跟家里开口要钱还网贷怎么办 网贷到家来要钱怎么办 网贷贷不了啦急要钱怎么办