mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 03:31:59 +00:00
1298. 曹冲养猪
https://www.acwing.com/problem/content/submission/code_detail/13684946/
This commit is contained in:
parent
aad9d251b1
commit
7a52adeeee
52
AcWing/1298/1298.cpp
Normal file
52
AcWing/1298/1298.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
|
||||
int n;
|
||||
long long a[N], b[N];
|
||||
|
||||
long long exgcd(long long a, long long b, long long &x, long long &y) {
|
||||
if (!b) {
|
||||
x = 1, y = 0;
|
||||
return a;
|
||||
}
|
||||
|
||||
long long g = exgcd(b, a % b, y, x);
|
||||
y -= a / b * x;
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
long long CRT() {
|
||||
long long mod = 1, ans = 0;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
mod *= a[i];
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
long long m = mod / a[i], x, y;
|
||||
exgcd(m, a[i], x, y);
|
||||
ans = (ans + b[i] * m * x % mod) % mod;
|
||||
}
|
||||
|
||||
return (ans % mod + mod) % mod;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
|
||||
cin >> n;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i] >> b[i];
|
||||
}
|
||||
|
||||
cout << CRT() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user