比赛 |
EYOI暨SBOI暑假快乐赛2nd |
评测结果 |
AWWAWAAAAA |
题目名称 |
曹冲养猪 |
最终得分 |
70 |
用户昵称 |
cb |
运行时间 |
0.001 s |
代码语言 |
C++ |
内存使用 |
0.73 MiB |
提交时间 |
2022-06-26 09:24:15 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
long long n, m = 1, ans = 0;
long long a[MAXN], b[MAXN];
long long exgcd (long long r1, long long r2, long long &x, long long &y) {
if (r2 == 0) { x = 1, y = 0; return r1; }
long long r3 = exgcd (r2, r1 % r2, x, y);
long long z = x; x = y; y = z - y * (r1 / r2);
return r3;
}
long long solve (long long r1, long long r2, long long mod) {
long long x0, y0, gc;
gc = exgcd (r1, mod, x0, y0); x0 = x0 * r2 / gc;
return x0;
}
int main () {
freopen ("ccyz.in", "r", stdin);
freopen ("ccyz.out", "w", stdout);
cin >> n;
for (int q = 1; q <= n; ++q) {
cin >> b[q] >> a[q]; m *= b[q];
}
for (int q = 1; q <= n; ++q) {
ans += a[q] * (m / b[q]) * solve (m / b[q], 1, b[q]); ans %= m;
}
cout << ans << endl;
return 0;
}