답안 #19310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19310 2016-02-24T09:24:54 Z hongjun7 Σ (kriii4_P2) C++
100 / 100
16 ms 1240 KB
#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);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1240 KB Output is correct
2 Correct 15 ms 1240 KB Output is correct
3 Correct 15 ms 1240 KB Output is correct
4 Correct 15 ms 1240 KB Output is correct
5 Correct 15 ms 1240 KB Output is correct
6 Correct 16 ms 1240 KB Output is correct
7 Correct 15 ms 1240 KB Output is correct
8 Correct 11 ms 1240 KB Output is correct
9 Correct 11 ms 1240 KB Output is correct
10 Correct 16 ms 1240 KB Output is correct
11 Correct 15 ms 1240 KB Output is correct
12 Correct 14 ms 1240 KB Output is correct
13 Correct 9 ms 1240 KB Output is correct
14 Correct 11 ms 1240 KB Output is correct
15 Correct 14 ms 1240 KB Output is correct
16 Correct 11 ms 1240 KB Output is correct
17 Correct 11 ms 1240 KB Output is correct
18 Correct 14 ms 1240 KB Output is correct
19 Correct 15 ms 1240 KB Output is correct
20 Correct 14 ms 1240 KB Output is correct