Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /**
  2. * Author : Dipu Kumar Mohanto (Dip)
  3. * CSE, BRUR.
  4. *
  5. * Problem : 412 - Pi
  6. * Category : Number Theory (gcd, pair)
  7. *
  8. * OJ : UVA Online Judge
  9. *
  10. * Verdict : Accepted
  11. *
  12. * Date : 27-10-2016 (11:32 AM)
  13. *
  14. * E-mail : dipukumarmohanto1@gmail.com
  15. *
  16. **/
  17.  
  18. #include <bits/stdc++.h>
  19.  
  20. using namespace std;
  21.  
  22. #define PI acos(-1.0)
  23.  
  24. int gcd(int a,int b) {
  25. while (b) {
  26. a %= b;
  27. a ^= b;
  28. b ^= a;
  29. a ^= b;
  30. } return a;
  31. }
  32.  
  33.  
  34. int main() {
  35. int n;
  36.  
  37. while (cin >> n, n) {
  38. vector <int> Vec;
  39.  
  40. for (int i=0; i<n; i++) {
  41. int num;
  42.  
  43. cin >> num;
  44.  
  45. Vec.push_back(num);
  46. }
  47.  
  48. int c = 0;
  49. int tpair = 0;
  50.  
  51. for (int i=0; i<n-1; i++) {
  52. for (int j=i+1; j<n; j++) {
  53. if (gcd(Vec[i], Vec[j]) == 1) c++;
  54. tpair++;
  55. }
  56. }
  57.  
  58. if (c == 0) {
  59. cout << "No estimate for this data set.\n";
  60. continue;
  61. }
  62.  
  63. double ans = (double)tpair*6/(double)c;
  64.  
  65. printf("%.6lf\n", sqrt(ans));
  66.  
  67. Vec.clear();
  68. }
  69. }
  70.  
  71.  
  72. Input :
  73. 5
  74. 2
  75. 3
  76. 4
  77. 5
  78. 6
  79. 2
  80. 13
  81. 39
  82. 14
  83. 11701
  84. 31316
  85. 20671
  86. 5786
  87. 12263
  88. 4313
  89. 24355
  90. 31185
  91. 20053
  92. 912
  93. 10808
  94. 1832
  95. 20945
  96. 4313
  97. 0
  98.  
  99. Output :
  100. 3.162278
  101. No estimate for this data set.
  102. 2.833622
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement