QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#622581 | #5301. Modulo Ruins the Legend | Foedere0 | WA | 0ms | 3588kb | C++20 | 1.7kb | 2024-10-08 23:02:04 | 2024-10-08 23:02:05 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int, int> PII;
const int N = 1000010;
unordered_map<int, int> mp;
int sum = 0;
int n, m;
int a[N];
int exgcd(int a, int b, int &x, int &y)
{
if (!b)
{
x = 1;
y = 0;
return a; // 到达递归边界开始向上一层返回
}
int d = exgcd(b, a % b, x, y);
int temp = y; // 推出这一层的x,y
y = x - (a / b) * y;
x = temp;
return d;
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
sum += a[i];
sum %= m;
}
// cout << sum << endl;
// int t = m - (sum % m);
int o = n, p = (n * (n + 1)) / 2;
// cout << o * 15 + p * -5 + sum << endl;
// cout << o << " " << p << endl;
// cout << p * 5 % m << endl;
int u = __gcd(o, p);
// cout << u << endl;
int x = __gcd(u, m);
// cout << x << endl;
int l = 0, r = 1e18;
while (l < r)
{
int mid = (l + r + 1) / 2;
if (mid * x <= sum)
{
l = mid;
}
else
r = mid - 1;
}
// cout << l << endl;
int ans = sum - (l * x);
cout << ans << endl;
int w, t;
exgcd(u, m, w, t);
w *= (-l);
// cout << w << endl;
// cout << w*l*u << " " << t << endl;
int xx, yy;
exgcd(o, p, xx, yy);
// cout << xx << " " << yy << endl;
cout << xx * w << " " << yy * w << endl;
}
signed main()
{
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3588kb
input:
6 24 1 1 4 5 1 4
output:
1 15 -5
result:
wrong answer Integer parameter [name=d] equals to -5, violates the range [0, 23]