QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#642906 | #5301. Modulo Ruins the Legend | FWKnightship | WA | 0ms | 3560kb | C++17 | 1.6kb | 2024-10-15 16:59:51 | 2024-10-15 16:59:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using vec = array<LL, 2>;
constexpr LL M1 = 1145140019, M2 = 1145140033, pw = 23333;
// a * x % b == gcd(a, b)
void exgcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1, y = 0;
return;
}
exgcd(b, a % b, y, x);
y -= a / b * x;
}
LL arr[100020];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
LL n, m;
cin >> n >> m;
LL n2 = n;
LL s = 0;
for (int i = 1; i <= n; ++i)
{
cin >> arr[i];
s += arr[i];
}
LL ss, dd;
if (n % 2)
{
LL g = gcd(n, m);
LL ans = s % g;
n /= g;
m /= g;
s /= g;
LL x, y;
exgcd(n, m, x, y);
// n * x % m == 1
ss = (x * (m - s) % m + m) % m;
cout << ans << "\n";
dd = 0;
}
else
{
LL nn = n;
n /= 2;
LL g = gcd(n, m);
LL ans = s % g;
n /= g;
m /= g;
s /= g;
LL x, y;
exgcd(n, m, x, y);
ss = x * (m - s);
cout << ans << "\n";
if (ss % 2)
{
ss = ((ss - (nn + 1)) / 2 % m + m) % m;
dd = 1;
}
else
{
ss = (ss / 2 % m + m) % m;
dd = 0;
}
}
cout << ss << " " << dd;
LL jxy = 0;
for (int i = 1; i <= n2; ++i)
{
jxy += arr[i] + ss + dd * i;
jxy %= m;
}
cout << '\n' << jxy;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3560kb
input:
6 24 1 1 4 5 1 4
output:
1 6 1 1
result:
wrong output format Extra information in the output file