Submission #19244

#TimeUsernameProblemLanguageResultExecution timeMemory
19244kaTkaHrΣ (kriii4_P2)C++14
100 / 100
742 ms1160 KiB
#include <stdio.h>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;

const int MX = 10005, MM = 1000000007;

ll pw(ll A, ll B){
	ll R = 1;
	while(B){
		if( B & 1 ) R = R * A % MM;
		A = A * A % MM; B /= 2;
	}
	return R;
}

ll rv(ll A){ return pw(A, MM-2); }

int N[MX], S[MX];

int main()
{
	int M;
	scanf("%d", &M);
	for(int i = 1; i <= M; i++){
		scanf("%d%d", N+i, S+i);
	}
	ll ans = 0;
	for(int i = 1; i <= M; i++){
		ll t = 1;
		for(int j = 1; j <= M; j++){
			if(i == j) t = t * S[j] % MM;
			else t = t * N[j] % MM;
		}
		ans = (ans + t) % MM;
	}
	for(int i = 1; i <= M; i++){
		ans = ans * rv(N[i]) % MM;
	}
	printf("%lld\n", ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...