当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1491:Pi

题目描述
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't have 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/π2


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/π2 ≈ 6/10
π ≈ 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.
输入解释
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.
输出解释
A line with a single real value is to be emitted for each input data set encountered. This value is the estimate π 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.
输入样例
5
2
3
4
5
6
2
13
39
0
输出样例
3.162278
No estimate for this data set.

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1491

最后修改于 2020-10-29T06:05:32+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000