Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Author : Dipu Kumar Mohanto (Dip)
- * CSE, BRUR.
- *
- * Problem : 412 - Pi
- * Category : Number Theory (gcd, pair)
- *
- * OJ : UVA Online Judge
- *
- * Verdict : Accepted
- *
- * Date : 27-10-2016 (11:32 AM)
- *
- * E-mail : dipukumarmohanto1@gmail.com
- *
- **/
- #include <bits/stdc++.h>
- using namespace std;
- #define PI acos(-1.0)
- int gcd(int a,int b) {
- while (b) {
- a %= b;
- a ^= b;
- b ^= a;
- a ^= b;
- } return a;
- }
- int main() {
- int n;
- while (cin >> n, n) {
- vector <int> Vec;
- for (int i=0; i<n; i++) {
- int num;
- cin >> num;
- Vec.push_back(num);
- }
- int c = 0;
- int tpair = 0;
- for (int i=0; i<n-1; i++) {
- for (int j=i+1; j<n; j++) {
- if (gcd(Vec[i], Vec[j]) == 1) c++;
- tpair++;
- }
- }
- if (c == 0) {
- cout << "No estimate for this data set.\n";
- continue;
- }
- double ans = (double)tpair*6/(double)c;
- printf("%.6lf\n", sqrt(ans));
- Vec.clear();
- }
- }
- Input :
- 5
- 2
- 3
- 4
- 5
- 6
- 2
- 13
- 39
- 14
- 11701
- 31316
- 20671
- 5786
- 12263
- 4313
- 24355
- 31185
- 20053
- 912
- 10808
- 1832
- 20945
- 4313
- 0
- Output :
- 3.162278
- No estimate for this data set.
- 2.833622
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement