#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[1005], b[1005];
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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
1096 KB |
futex (syscall #202) was called by the program (disallowed syscall) |
2 |
Halted |
0 ms |
0 KB |
- |