QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654886 | #5301. Modulo Ruins the Legend | WA_automaton# | RE | 0ms | 3668kb | C++20 | 1.9kb | 2024-10-18 22:44:34 | 2024-10-18 22:44:35 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
void debug() {std::cerr << "\n";}
template<class T, class... OtherArgs>
void debug(T &&var, OtherArgs &&... args) {
std::cerr << std::forward<T>(var) << " ";
debug(std::forward<OtherArgs>(args)...);
}
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using i64 = long long;
using u64 = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
constexpr int N = 1000010;
constexpr int P = 998244353;
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;
}
int solve(int a, int b, int p) {
int x, y;
int d = exgcd(a, p, x, y);
if (b % d) {
return -1; // no solution
}
return (x * (b / d) % (p / d) + (p / d)) % (p / d); // 最小正整数解
}
void solve() {
int n, m;
cin >> n >> m;
int s = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
s += x;
}
// if (s % m == 0) {
// cout << "0\n";
// cout << "0 0\n";
// return;
// }
int a = gcd(n, m), b = gcd(n * (n + 1) / 2, m);
int d = gcd(a, b);
int r = m - s % m;
int mn = (s + (r + d - 1) / d * d) % m;
cout << mn << '\n';
a = n, b = n * (n + 1) / 2;
int x = solve((a + b) % m, (mn - s % m + m) % m, m);
cout << x << ' ' << x << '\n';
// debug("?", r, mn, x, (n * x + n * (n + 1) / 2 * x + s) % m);
assert((n * x + n * (n + 1) / 2 * x + s) % m == mn);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
int _ = 1;
// cin >> _;
while (_--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
6 24 1 1 4 5 1 4
output:
1 3 3
result:
ok ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
7 29 1 9 1 9 8 1 0
output:
0 0 0
result:
ok ok
Test #3:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
1 1 0
output:
0 0 0
result:
ok ok
Test #4:
score: -100
Runtime Error
input:
1 1000000000 963837005