Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdio>
  4. #include <stdio.h>
  5. #include <string>
  6. #include <cstring>
  7. #include <cmath>
  8. #include <bits/stdc++.h>
  9. #include <algorithm>
  10. #include <set>
  11. #include <map>
  12. #include <vector>
  13.  
  14. using namespace std;
  15.  
  16. #define pb push_back
  17. #define mp make_pair
  18. #define x first
  19. #define y second
  20.  
  21. typedef long long ll;
  22. typedef long double ld;
  23.  
  24. const int N = (int) 1e3;
  25. const int INF = (int) 1e9;
  26. const ld EPS = (ld) 1e-9;
  27.  
  28. ll a1, b1;
  29. ll d[10], a[10];
  30.  
  31. ll gcd(ll a, ll b){
  32. if (b == 0)
  33. return a;
  34. return gcd(b, a % b);
  35. }
  36.  
  37. ll slc(ll q1, ll q2, ll p1, ll p2){
  38. return q1 * p2 + p1 * q2;
  39. }
  40.  
  41. ll slz(ll q2, ll p2){
  42. return q2 * p2;
  43. }
  44.  
  45. void check(ll n, ll x){
  46. ll cnt = 0;
  47. ll pr = 1;
  48. for (ll i = 0; i < n; i++)
  49. if (d[i] == 1){
  50. cnt++;
  51. pr *= a[i];
  52. }
  53. if (cnt == x){
  54. a1 = slc(a1, b1, 1, pr);
  55. b1 = slz(b1, pr);
  56. ll nod = gcd(a1, b1);
  57. a1 /= nod;
  58. b1 /= nod;
  59. }
  60. }
  61.  
  62. void go(ll i, ll n, ll x){
  63. d[i] = 0;
  64. if (i == n - 1)
  65. check(n, x);
  66. else
  67. go(i + 1, n, x);
  68. d[i] = 1;
  69. if (i == n - 1)
  70. check(n, x);
  71. else
  72. go(i + 1, n, x);
  73. }
  74.  
  75. int main(){
  76. ll n, ansa = 0, ansb = 1, nod;
  77. cin >> n;
  78. for (ll i = 0; i < n; i++)
  79. cin >> a[i];
  80. sort(a, a + n);
  81. for (ll i = 0; i < n; i++){
  82. a1 = 0;
  83. b1 = 1;
  84. go(0, n, i + 1);
  85. ll c = 1;
  86. for (ll j = 0; j < i + 2; j++)
  87. c *= a[0];
  88. c *= (i + 1);
  89. a1 = a1 * c;
  90. b1 = b1 * (i + 2);
  91. nod = gcd(a1, b1);
  92. a1 /= nod;
  93. b1 /= nod;
  94. if (i % 2 != 0)
  95. a1 = -a1;
  96. ansa = slc(ansa, ansb, a1, b1);
  97. ansb = slz(ansb, b1);
  98. nod = gcd(ansa, ansb);
  99. ansa /= nod;
  100. ansb /= nod;
  101. }
  102. nod = gcd(ansa, ansb);
  103. if (nod == 0)
  104. nod = 1;
  105. cout << ansa / nod << '/' << ansb / nod << endl;
  106. return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement