QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692088#5301. Modulo Ruins the LegendCalculatelove#RE 0ms3904kbC++14894b2024-10-31 13:47:222024-10-31 13:47:23

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 13:47:23]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3904kb
  • [2024-10-31 13:47:22]
  • 提交

answer

#include <bits/stdc++.h>

typedef long long s64;

s64 exgcd(s64 a, s64 b, s64 &x, s64 &y) {
    if (!b) { x = 1, y = 0; return a; }
    s64 d = exgcd(b, a % b, x, y);
    s64 z = x; x = y, y = z - (a / b) * y;
    return d;
}

int n, m;

int main() {
    scanf("%d%d", &n, &m);

    s64 sum = 0;
    for (int i = 1, x; i <= n; i ++) {
        scanf("%d", &x);
        sum = (sum + x) % m;
    }

    s64 x, y;
    s64 d = exgcd(n, 1ll * n * (n + 1) / 2, x, y);

    d %= m;
    x %= m; if (x < 0) x += m;
    y %= m; if (y < 0) y += m;

    s64 step = (m - sum) / d + ((m - sum) % d != 0);
    s64 next_sum = (sum + step * d) % m;

    if (sum <= next_sum) {
        printf("%lld\n", sum);
        puts("0 0");
    } else {
        printf("%lld\n", next_sum);
        printf("%lld %lld\n", 1ll * x * step % m, 1ll * y * step % m);
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3904kb

input:

6 24
1 1 4 5 1 4

output:

1
15 3

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3892kb

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

score: -100
Runtime Error

input:

1 1
0

output:


result: