QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623854 | #5301. Modulo Ruins the Legend | adivse# | RE | 0ms | 3656kb | C++20 | 895b | 2024-10-09 14:13:19 | 2024-10-09 14:13:19 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 100005;
const int inf = 1e9;
int n, m, a, q;
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int g = exgcd(b, a % b, x, y);
int temp = x;
x = y;
y = temp - (a / b) * y;
return g;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
int x; cin >> x;
q += x; q %= m;
}
int x, y, g;
g = exgcd(n, n * (n + 1) / 2, x, y);
g %= m;
if (q % g <= (g - (m - q) % g) % g) {
x = -x * (q / g) % m;
y = -y * (q / g) % m;
cout << q % g << endl;
} else {
x = x * ((m - q) / g);
y = y * ((m - q) / g);
cout << (g - (m - q) % g) % g << endl;
}
x = (x % m + m) % m;
y = (y % m + m) % m;
cout << x << ' ' << y << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
6 24 1 1 4 5 1 4
output:
1 15 19
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3656kb
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