QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75387 | #5301. Modulo Ruins the Legend | team1377# | RE | 2ms | 3772kb | C++14 | 696b | 2023-02-05 08:33:48 | 2023-02-05 08:33:49 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int exgcd(int a, int b, int &x, int &y)
{
if (!b) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
signed main()
{
int n, m, s = 0;
scanf("%lld%lld", &n, &m);
for (int i = 1, x; i <= n; ++i) {
scanf("%lld", &x);
s += x;
}
s %= m;
int p = n % m, q = 1ll * n * (n + 1) / 2 % m, x, y;
int d = exgcd(p, q, x, y);
int cs = ((m - s) % m + d - 1) / d;
printf("%lld\n%lld %lld\n", (s + 1ll * cs * d) % m, (1ll * x * cs % m + m) % m, (1ll * y * cs % m + m) % m);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
6 24 1 1 4 5 1 4
output:
1 15 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3772kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: -100
Runtime Error
input:
1 1 0