답안 #20080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
20080 2016-02-25T10:39:15 Z sui Σ (kriii4_P2) C++14
100 / 100
19 ms 1884 KB
#define _CRT_SECURE_NO_WARNINGS // scanf(), gets() (needed for Visual C++)

//#define NDEBUG
#include <cassert>

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>

#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <deque>

using namespace std;

#define MEMSET(x, WITH) memset(x, (WITH), sizeof(x))
#define FOR(i, E) for(int i=0; i<(E); i++)
#define REP(i, LO, HI) for(int i=(LO); i<=(HI); i++)

#define GETINT(x) scanf("%d", &x)
#define GETDBL(x) scanf("%lf", &x)
#define GETSTR(x) scanf("%s", x)
#define NEWINT(x) int x; scanf("%d", &x)
#define NEWDBL(x) double x; scanf("%lf", &x)
#define NEWLN putchar('\n')

#ifdef _WIN32
#define popcnt __popcnt
#else
#define popcnt __builtin_popcount
#endif

typedef long long ll;
//const ll MOD = 1000000007;
//const double PI = atan(1) * 4;







const ll MOD = 1000000007;

ll powerMod(ll a, ll n) {
	ll ans = 1;
	for (int i=62; i>=0; i--) {
		ans = ans * ans % MOD;
		if ((n>>i)&1)
			ans = ans * a % MOD;
	}
	return ans;
}


ll a[10333];
ll b[10333];
ll ans;

int main() {
	int M; cin >> M;
	FOR(i, M) cin >> b[i] >> a[i];



	ll denom = 1;
	FOR(i, M) denom = denom * b[i] % MOD;
	
	ll numer = 0;
	FOR(i, M) {
		ll n = a[i] * denom % MOD * powerMod(b[i], MOD-2) % MOD;
		
		numer = (numer + n) % MOD;
	}


	ans = numer * powerMod(denom, MOD-2) % MOD;
	cout << ans << endl;
	


	/*
	ans = 0;
	FOR(i, M) {
		ll term = a[i] * powerMod(b[i], MOD-2) % MOD;
		ans += term;
		ans %= MOD;
	}
	cout << ans << endl;
	*/


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 1884 KB Output is correct
2 Correct 14 ms 1884 KB Output is correct
3 Correct 17 ms 1884 KB Output is correct
4 Correct 9 ms 1884 KB Output is correct
5 Correct 15 ms 1884 KB Output is correct
6 Correct 11 ms 1884 KB Output is correct
7 Correct 14 ms 1884 KB Output is correct
8 Correct 14 ms 1884 KB Output is correct
9 Correct 19 ms 1884 KB Output is correct
10 Correct 15 ms 1884 KB Output is correct
11 Correct 18 ms 1884 KB Output is correct
12 Correct 18 ms 1884 KB Output is correct
13 Correct 14 ms 1884 KB Output is correct
14 Correct 19 ms 1884 KB Output is correct
15 Correct 15 ms 1884 KB Output is correct
16 Correct 12 ms 1884 KB Output is correct
17 Correct 13 ms 1884 KB Output is correct
18 Correct 16 ms 1884 KB Output is correct
19 Correct 19 ms 1884 KB Output is correct
20 Correct 13 ms 1884 KB Output is correct