QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700309#5301. Modulo Ruins the LegendHe_ng#WA 0ms3644kbC++201.7kb2024-11-02 12:41:072024-11-02 12:41:35

Judging History

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

  • [2024-11-02 12:41:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-11-02 12:41:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int N = 1e6;
const int M = 2e3;
int pow(int a, int b, int m) {
    int ans = 1;
    a %= m;
    while (b) {
        if (b & 1)
            ans = (ans % m) * (a % m) % m;
        b /= 2;
        a = (a % m) * (a % m) % m;
    }
    ans %= m;
    return ans;
}
int extgcd(int a, int b, int &x, int &y)
// 求解ax+by=gcd(a, b)
// 返回值为gcd(a, b)
{
    int d = a;
    if (b) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else
        x = 1, y = 0;
    return d;
}
int mod_inverse(int a, int m)
// 求解a关于模上m的逆元
// 返回-1表示逆元不存在
{
    int x, y;
    int d = extgcd(a, m, x, y);
    return d == 1 ? (m + x % m) % m : -1;
}
void extend_gcd(int a, int b, int &d, int &x, int &y) {
    if (!b) {
        d = a;
        x = 1;
        y = 0;
    } else {
        extend_gcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n + 1);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
        sum %= m;
    }
    if (sum % m == 0) {
        cout << 0 << endl
             << 0 << " " << 0 << endl;
        return;
    }
    int g = __gcd(n, n * (n + 1) / 2);
    int k = (m - sum + g - 1) / g;
    int s, d;
    int t;
    extend_gcd(n, n * (n + 1) / 2, t, s, d);
    cout
        << (sum + k * g) % m << endl;
    cout << (s + m) % m << " " << (d + m) % m << endl;
    return;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

6 24
1 1 4 5 1 4

output:

1
21 1

result:

wrong answer Result not equal to solution.