'commit'
This commit is contained in:
35
TangDou/AcWing_TiGao/T5/TongYu/1298.cpp
Normal file
35
TangDou/AcWing_TiGao/T5/TongYu/1298.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define int long long
|
||||
#define endl "\n"
|
||||
const int N = 10;
|
||||
|
||||
int n;
|
||||
int a[N], m[N];
|
||||
|
||||
void exgcd(int a, int b, int &x, int &y) {
|
||||
if (!b)
|
||||
x = 1, y = 0;
|
||||
else {
|
||||
exgcd(b, a % b, y, x);
|
||||
y -= a / b * x;
|
||||
}
|
||||
}
|
||||
|
||||
signed main() {
|
||||
cin >> n;
|
||||
int M = 1;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> m[i] >> a[i];
|
||||
M *= m[i];
|
||||
}
|
||||
|
||||
int res = 0, x, y;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
exgcd(M / m[i], m[i], x, y);
|
||||
res += a[i] * M / m[i] * x;
|
||||
}
|
||||
|
||||
cout << (res % M + M) % M << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user