# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19310 | hongjun7 | Σ (kriii4_P2) | C++98 | 16 ms | 1240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
int mod = 1e9 + 7;
long long f(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
long long v = f(a, b / 2);
v = (v*v) % mod;
if (b & 1) v = (v*a) % mod;
return v;
}
long long mul(long long a, long long b) {
return (a*b) % mod;
}
long long div(long long a, long long b) {
return (a * f(b, mod - 2)) % mod;
}
long long a[10005], b[10005];
int main() {
int m;
long long N = 1, X = 0;
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%lld%lld", &b[i], &a[i]);
N = mul(N, b[i]);
}
for (int i = 1; i <= m; i++) {
long long g = div(N, b[i]);
long long v = mul(a[i], g);
X = (X + v) % mod;
}
X = div(X, N);
printf("%lld", X);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |