但是答案确乎可以是 $3$?毕竟只有 $3$ 个人的话按照题面要求的数没有什么问题……
#include <bits/stdc++.h>
using namespace std;
void exgcd(long long a, long long b, long long &x, long long &y) {
// ax + by = gcd(a, b)
if (b == 0) {
x = 1; y = 0; return;
}
exgcd(b, a % b, x, y);
int t = x;
x = y;
y = t - (a / b) * y;
}
int n;
long long b[100001], a[100001], t[100001];
long long unsigned prod = 1, ans;
int main() {
// scanf("%d", &n);
n = 4;
a[1] = 5; a[2] = 9; a[3] = 13; a[4] = 17;
b[1] = b[2] = b[3] = b[4] = 3;
for (int i = 1; i <= n; ++i) {
// scanf("%lld%lld", &a[i], &b[i]);
prod *= a[i];
}
for (int i = 1; i <= n; ++i) {
t[i] = prod / a[i];
long long x, y;
exgcd(t[i], a[i], x, y);
x = (x % a[i] + a[i]) % a[i];
ans += b[i] * t[i] * x;
}
printf("%llu\n", ans % prod);
}
|