Submission #19310

#TimeUsernameProblemLanguageResultExecution timeMemory
19310hongjun7Σ (kriii4_P2)C++98
100 / 100
16 ms1240 KiB
#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 timeMemoryGrader output
Fetching results...