QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#75387#5301. Modulo Ruins the Legendteam1377#RE 2ms3772kbC++14696b2023-02-05 08:33:482023-02-05 08:33:49

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-05 08:33:49]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3772kb
  • [2023-02-05 08:33:48]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

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;
}

signed main()
{
    int n, m, s = 0;
    scanf("%lld%lld", &n, &m);
    for (int i = 1, x; i <= n; ++i) {
        scanf("%lld", &x);
        s += x;
    }
    s %= m;
    int p = n % m, q = 1ll * n * (n + 1) / 2 % m, x, y;
    int d = exgcd(p, q, x, y);
    int cs = ((m - s) % m + d - 1) / d;
    printf("%lld\n%lld %lld\n", (s + 1ll * cs * d) % m, (1ll * x * cs % m + m) % m, (1ll * y * cs % m + m) % m);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 24
1 1 4 5 1 4

output:

1
15 3

result:

ok ok

Test #2:

score: 0
Accepted
time: 2ms
memory: 3772kb

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: