QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213973 | #5301. Modulo Ruins the Legend | sundage | WA | 0ms | 3656kb | C++17 | 1.2kb | 2023-10-14 16:49:47 | 2023-10-14 16:49:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m;
int a[100005];
int sum = 0;
int extend_gcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int d = extend_gcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
sum %= m;
int cnt = sum;
sum = m - sum;
int xx = n * (n + 1) / 2;
int yy = n;
int s = 0, d = 0;
int q = extend_gcd(yy, xx, s, d);
int s1 = 0, d1 = 0;
int t = extend_gcd(q, m, d1, s1);
int ans = 0;
if (sum % t) {
ans = ((sum / t) + 1) * t - sum;
} else {
ans = (sum / t) * t - sum;
}
d1 *= ((ans - sum) / t) % m;
d1 %= m;
d = d1 * d, s = d1 * s;
s %= m;
d %= m;
s += m;
d += m;
s %= m;
d %= m;
if (ans > cnt) {
cout << cnt << endl;
cout << 0 << " " << 0 << endl;
return;
}
cout << ans << endl;
cout << s << " " << d << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
//813586357 839886562
//877878853 839886562
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3656kb
input:
6 24 1 1 4 5 1 4
output:
1 6 22
result:
wrong answer Result not equal to solution.