Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. // Accepted
  2. // Time : 0.076
  3.  
  4. #include <iostream>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <algorithm>
  8. #define N 51
  9. using namespace std;
  10.  
  11. int ar[N],l=0;
  12.  
  13. int gcd (int a , int b)
  14. {
  15. //int r=1;
  16.  
  17. if (a>b)
  18. {
  19. swap(a,b);
  20. }
  21.  
  22. int r=1;
  23.  
  24. while (r!=0)
  25. {
  26. r = b%a;
  27. b = a;
  28. a = r;
  29. }
  30.  
  31. return b;
  32. }
  33.  
  34. int main()
  35. {
  36. int cnt;
  37.  
  38. int n;
  39.  
  40. while (cin >> n)
  41. {
  42. if (n==0)
  43. {
  44. break;
  45. }
  46.  
  47. for (int i=0;i<n;i++)
  48. {
  49. cin >> ar[i];
  50. }
  51.  
  52. cnt = 0;
  53. int sonn = n*(n-1)/2; // Set of Natural Number = (n*(n-1))/2;
  54.  
  55. for (int i=0;i<n-1;i++)
  56. {
  57. for (int j=i+1;j<n;j++)
  58. {
  59. if (gcd(ar[i],ar[j]) == 1)
  60. {
  61. //printf("(%d %d) ",ar[i],ar[j]);
  62. cnt++;
  63. }
  64. }
  65. }
  66.  
  67. if (cnt == 0)
  68. {
  69. printf ("No estimate for this data set.\n");
  70. }
  71.  
  72. else
  73. {
  74. printf("%.6lf\n",sqrt((1.0*6.0*sonn)/cnt));
  75. }
  76. }
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement