QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671739 | #5301. Modulo Ruins the Legend | bessie_goes_moo# | WA | 0ms | 3676kb | C++14 | 1.3kb | 2024-10-24 14:16:53 | 2024-10-24 14:16:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int T, n, a[N], m, sum;
inline int read() {
int al = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
fh = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
al = al * 10 + ch - '0';
ch = getchar();
}
return al * fh;
}
int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
map<int, int> ma;
int cel(int a, int b) {
return a % b == 0 ? a / b : a / b + 1;
}
void exgcd(int a,int b,int &x,int &y)
{
if(!b)
{
x=1;
y=0;
return;
}
int p;
exgcd(b,a%b,x,y);
p=x;
x=y;
y=p-(a/b)*y;
return;
}
signed main() {
n = read();
m = read();
for (int i = 1; i <= n; i++) {
a[i] = read();
sum += a[i];
}
int s = sum % m, g = gcd(n, n * (n + 1) / 2) % m, ans = 0, now = 0, chu = 0;
ans = s;
int ans_chu = 0;
now = s;
if (g == 0)
{
cout << "0 0";
return 0;
}
while (ma[now] == 0) {
ma[now] = 1;
int u = cel(m - now, g);
now += u * g;
now %= m;
chu += u;
if (now < ans) {
ans = now;
ans_chu = chu;
}
}
int x, y;
exgcd(n, (n + 1)*n / 2, x, y);
x=(x%m+m)%m;
y=(y%m+m)%m;
x*=ans_chu;
x%=m;
y*=ans_chu;
y%=m;
cout << x << " " << y << endl;
//cout << ans << " " << ans_chu << endl;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3676kb
input:
6 24 1 1 4 5 1 4
output:
15 3
result:
wrong output format Unexpected end of file - int32 expected