QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621557 | #5301. Modulo Ruins the Legend | wdw | WA | 0ms | 3616kb | C++20 | 3.4kb | 2024-10-08 15:21:54 | 2024-10-08 15:21:56 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define int long long
const int N = 2e5 + 5;
const double eps = 1e-10;
int x, y;
//ax+by=c
//裴蜀定理得c%gcd(a,b)==0才有解 解ax=c(mod b)=ax+by=c 可解得x=x0*c/gcd(a,b),此时mod(b(b值会变化)/gcd(a,b))
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int x1, y1;
int d = exgcd(b, a % b, x1, y1);
x = y1, y = x1 - a / b * y1;
return d;
}
void solve() {
int n, m;
cin >> n >> m;
int s = 0;
for (int i = 1, x; i <= n; i++) {
cin >> x;
s += x;
s %= m;
}
int a = n;
x = 0, y = 0;
int d = exgcd(a, m, x, y);
s = m - s;
if (s % d == 0) {
x *= s / d;
cout << 0 << '\n';
int l = m / d;
x %= l;
x += l;
x %= l;
cout << x << " " << 0 << '\n';
return;
}
a = (n) * (n + 1) / 2;
x = 0, y = 0;
d = exgcd(a, m, x, y);
if (s % d == 0) {
x *= s / d;
cout << 0 << '\n';
int l = m / d;
x %= l;
x += l;
x %= l;
cout << 0 << " " << x << '\n';
return;
}
for (int i = 1; i <= n; i++) {
s++;
s %= m;
a = n;
x = 0, y = 0;
d = exgcd(a, m, x, y);
if (s % d == 0) {
x *= s / d;
cout << i << '\n';
int l = m / d;
x %= l;
x += l;
x %= l;
cout << x << " " << 0 << '\n';
return;
}
int l = m / d;
x %= l;
x += l;
x %= l;
int p = s;
p = p - x * a % m;
p %= m;
p += m;
p %= m;
int dx = x;
a = (n) * (n + 1) / 2;
x = 0, y = 0;
d = exgcd(a, m, x, y);
// cout<<p<<'\n';
if (p % d == 0) {
x *= p / d;
//cout << i << '\n';
int l = m / d;
// cout<<x<<" "<<l<<'\n';
x %= l;
x += l;
x %= l;
cout << dx << " " << x << '\n';
return;
}
a = (n) * (n + 1) / 2;
x = 0, y = 0;
d = exgcd(a, m, x, y);
if (s % d == 0) {
x *= s / d;
cout << i << '\n';
int l = m / d;
// cout<<x<<" "<<l<<'\n';
x %= l;
x += l;
x %= l;
cout << 0 << " " << x << '\n';
return;
}
l = m / d;
// cout<<x<<" "<<l<<'\n';
x %= l;
x += l;
x %= l;
p = s;
p = p - x * a % m;
p %= m;
p += m;
p %= m;
dx = x;
a = n;
x = 0, y = 0;
d = exgcd(a, m, x, y);
if (p % d == 0) {
x *= p / d;
cout << i << '\n';
int l = m / d;
// cout<<x<<" "<<l<<'\n';
x %= l;
x += l;
x %= l;
cout << x << " " << dx << '\n';
return;
}
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// cout << fixed << setprecision(10);
int T = 1;
//cin >> T;
while (T--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
input:
6 24 1 1 4 5 1 4
output:
1 7
result:
wrong output format Unexpected end of file - int32 expected