# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19245 | kaTkaHr | Σ (kriii4_P2) | C++14 | 3 ms | 1428 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
const int MX = 105, MM = 1000000007;
ll rv(ll A){
ll R = 1, B = MM-2;
while(B){
if( B&1 ) R = R * A % MM;
A = A * A % MM; B /= 2;
}
return R;
}
struct frac{
ll A, B;
frac(ll A, ll B):A(A), B(B){}
frac(){A = 0, B = 1;}
frac operator+ (const frac &l)const{
return frac((A * l.B + B * l.A) % MM, B * l.B % MM);
}
frac operator*(const frac &l)const{
return frac(A*l.A % MM, B*l.B % MM);
}
frac operator/(const frac &l)const{
return frac(A*l.B % MM, B*l.A % MM);
}
frac operator- (const frac &l)const{
return frac((A*l.B - B*l.A%MM + MM) % MM, B*l.B % MM);
}
ll v(){ return A * rv(B) % MM; }
};
frac D[MX][MX], I[MX][MX];
int P, Q, N, K;
void print()
{
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
printf("%lld,%lld ", D[i][j].A, D[i][j].B);
}
printf("\n");
}
printf("\n");
}
int main()
{
int M;
frac ans = frac(0, 1);
scanf("%d", &M);
for(int i = 1; i <= M; i++){
int N, S;
scanf("%d%d", &N, &S);
ans = ans + frac(S, N);
}
printf("%lld\n", ans.v());
/*
scanf("%d%d%d%d", &P, &Q, &N, &K);
for(int i = 1; i <= N; i++){
D[i][i] = I[i][i] = frac(1, 1);
if( i <= N-2 ) D[i][i+1] = frac(MM-Q, P);
if( i >= 3) D[i][i-1] = frac(MM-P+Q, P);
}
print();
for(int i = 1; i <= N; i++){
for(int j = i+1; j <= N; j++){
frac p = D[j][i] / D[i][i];
for(int k = 1; k <= N; k++){
D[j][k] = D[j][k] - D[i][k] * p;
I[j][k] = I[j][k] - I[i][k] * p;
}
}
}
for(int i = N; i >= 1; i--){
for(int j = i-1; j >= 1; j--){
frac p = D[j][i] / D[i][i];
for(int k = N; k >= 1; k--){
D[j][k] = D[j][k] - D[i][k] * p;
I[j][k] = I[j][k] - I[i][k] * p;
}
}
}
for(int i = 1; i <= N; i++){
frac p = frac(1, 1) / D[i][i];
for(int j = 1; j <= N; j++){
D[i][j] = D[i][j] * p;
I[i][j] = I[i][j] * p;
}
}
print();
for(int i = 1; i <= N; i++){
for(int j = 1; j <= N; j++){
printf("%lld ", I[i][j].v());
}
printf("\n");
}
printf("%lld", I[N][K].v());*/
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |