Submission #19332

# Submission time Handle Problem Language Result Execution time Memory
19332 2016-02-24T09:55:17 Z exqt Σ (kriii4_P2) C++
100 / 100
28 ms 2000 KB
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <cstring>
#include <map>
using namespace std;

#define in cin
#define out cout
#define ll long long int

ll DV = 1000000007;
ll mypow(ll a, ll b)
{
    ll t = a;
    ll res = 1;
    while(b)
    {
        if(b%2) res = (res * t) % DV;
        t = t % DV;
        t = (t*t) % DV;
        b = b >> 1;
    }

    return res;
}

ll myinv(ll a)
{
    return mypow(a, DV-2);
}

int main()
{
    int n; in >> n;
    ll mb = 1;
    vector<ll> va, vb;
    for(int i=0; i<n; i++)
    {
        ll a, b; in >> b >> a;
        va.push_back(a);
        vb.push_back(b);
        mb *= b; mb %= DV;
    }

    ll u = 0;
    for(int i=0; i<n; i++)
    {
        u += ((va[i]%DV)*(mb%DV)%DV)*(myinv(vb[i])%DV);
        u %= DV;
    }

    out << (u)*(myinv(mb))%DV;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2000 KB Output is correct
2 Correct 24 ms 2000 KB Output is correct
3 Correct 24 ms 2000 KB Output is correct
4 Correct 23 ms 2000 KB Output is correct
5 Correct 28 ms 2000 KB Output is correct
6 Correct 23 ms 2000 KB Output is correct
7 Correct 27 ms 2000 KB Output is correct
8 Correct 24 ms 2000 KB Output is correct
9 Correct 23 ms 2000 KB Output is correct
10 Correct 27 ms 2000 KB Output is correct
11 Correct 26 ms 2000 KB Output is correct
12 Correct 26 ms 2000 KB Output is correct
13 Correct 24 ms 2000 KB Output is correct
14 Correct 28 ms 2000 KB Output is correct
15 Correct 23 ms 2000 KB Output is correct
16 Correct 22 ms 2000 KB Output is correct
17 Correct 28 ms 2000 KB Output is correct
18 Correct 28 ms 2000 KB Output is correct
19 Correct 26 ms 2000 KB Output is correct
20 Correct 27 ms 2000 KB Output is correct