Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <stdio.h>
- #include <string>
- #include <cstring>
- #include <cmath>
- #include <bits/stdc++.h>
- #include <algorithm>
- #include <set>
- #include <map>
- #include <vector>
- using namespace std;
- #define pb push_back
- #define mp make_pair
- #define x first
- #define y second
- typedef long long ll;
- typedef long double ld;
- const int N = (int) 1e3;
- const int INF = (int) 1e9;
- const ld EPS = (ld) 1e-9;
- ll a1, b1;
- ll d[10], a[10];
- ll gcd(ll a, ll b){
- if (b == 0)
- return a;
- return gcd(b, a % b);
- }
- ll slc(ll q1, ll q2, ll p1, ll p2){
- return q1 * p2 + p1 * q2;
- }
- ll slz(ll q2, ll p2){
- return q2 * p2;
- }
- void check(ll n, ll x){
- ll cnt = 0;
- ll pr = 1;
- for (ll i = 0; i < n; i++)
- if (d[i] == 1){
- cnt++;
- pr *= a[i];
- }
- if (cnt == x){
- a1 = slc(a1, b1, 1, pr);
- b1 = slz(b1, pr);
- ll nod = gcd(a1, b1);
- a1 /= nod;
- b1 /= nod;
- }
- }
- void go(ll i, ll n, ll x){
- d[i] = 0;
- if (i == n - 1)
- check(n, x);
- else
- go(i + 1, n, x);
- d[i] = 1;
- if (i == n - 1)
- check(n, x);
- else
- go(i + 1, n, x);
- }
- int main(){
- ll n, ansa = 0, ansb = 1, nod;
- cin >> n;
- for (ll i = 0; i < n; i++)
- cin >> a[i];
- sort(a, a + n);
- for (ll i = 0; i < n; i++){
- a1 = 0;
- b1 = 1;
- go(0, n, i + 1);
- ll c = 1;
- for (ll j = 0; j < i + 2; j++)
- c *= a[0];
- c *= (i + 1);
- a1 = a1 * c;
- b1 = b1 * (i + 2);
- nod = gcd(a1, b1);
- a1 /= nod;
- b1 /= nod;
- if (i % 2 != 0)
- a1 = -a1;
- ansa = slc(ansa, ansb, a1, b1);
- ansb = slz(ansb, b1);
- nod = gcd(ansa, ansb);
- ansa /= nod;
- ansb /= nod;
- }
- nod = gcd(ansa, ansb);
- if (nod == 0)
- nod = 1;
- cout << ansa / nod << '/' << ansb / nod << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement