#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#define INFL 90000000000000000
#define PI 3.141592653589793238462643383279502884
#define SQ(a) ((a)*(a))
#define pb push_back
#define mod 1000000007
typedef long long ll;
typedef long double ld;
typedef double dd;
typedef std::pair<int,int> pii;
using namespace std;
ll m,n[11111],s[11111],inv,at,bt,a,b;
ll in(ll a){
a%=mod;
ll ret=1;
ll x=mod-2;
while(x){
if(x%2){
ret=ret*a%mod;
}
a=a*a%mod;
x/=2;
}
return ret;
}
int main(){
at=1;
bt=1;
scanf("%lld",&m);
for(int i=0;i<m;i++){
scanf("%lld%lld",&n[i],&s[i]);
at=at*n[i]%mod;
}
a = in(at);
b=0;
for(int i=0;i<m;i++){
inv=in(n[i]);
b=(b+inv*at%mod*s[i]%mod)%mod;
}
printf("%lld",a*b%mod);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1256 KB |
Output is correct |
2 |
Correct |
7 ms |
1256 KB |
Output is correct |
3 |
Correct |
7 ms |
1256 KB |
Output is correct |
4 |
Correct |
6 ms |
1256 KB |
Output is correct |
5 |
Correct |
7 ms |
1256 KB |
Output is correct |
6 |
Correct |
7 ms |
1256 KB |
Output is correct |
7 |
Correct |
7 ms |
1256 KB |
Output is correct |
8 |
Correct |
7 ms |
1256 KB |
Output is correct |
9 |
Correct |
5 ms |
1256 KB |
Output is correct |
10 |
Correct |
3 ms |
1256 KB |
Output is correct |
11 |
Correct |
6 ms |
1256 KB |
Output is correct |
12 |
Correct |
6 ms |
1256 KB |
Output is correct |
13 |
Correct |
7 ms |
1256 KB |
Output is correct |
14 |
Correct |
6 ms |
1256 KB |
Output is correct |
15 |
Correct |
6 ms |
1256 KB |
Output is correct |
16 |
Correct |
3 ms |
1256 KB |
Output is correct |
17 |
Correct |
6 ms |
1256 KB |
Output is correct |
18 |
Correct |
7 ms |
1256 KB |
Output is correct |
19 |
Correct |
6 ms |
1256 KB |
Output is correct |
20 |
Correct |
6 ms |
1256 KB |
Output is correct |