QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#269495#5738. Square Sumucup-team1198#WA 17ms3632kbC++201.7kb2023-11-29 17:42:012023-11-29 17:42:01

Judging History

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

  • [2023-11-29 17:42:01]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3632kb
  • [2023-11-29 17:42:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

#define int int64_t

int get2(int z, int k) {
    z %= (1ll << k);
    if (k == 0) return 1;
    if (k == 1) return 2;
    if (k == 2) {
        if (z == 0) return 4;
        if (z == 1) return 8;
        if (z == 2) return 4;
        return 0;
    }
    if (z % 4 == 0) {
        return get2(z / 4, k - 2) * 4;
    }
    if (z % 8 == 2 || z % 8 == 1 || z % 8 == 5) {
        return (1ll << (k + 1));
    }
    return 0;
}

int getp(int z, int p) {
    z %= p;
    int x = -1;
    int res = 1;
    int n = (p - 1) / 2;
    while (n) {
        if (n % 2 == 0) {
            x *= x;
            n /= 2;
        } else {
            res *= x;
            n--;
        }
    }
    if (z == 0) {
        if (res == 1) {
            return 2 * p - 1;
        } else {
            return 1;
        }
    }
    return p - res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int m, n;
    cin >> m >> n;
    for (int i = 0; i < n; ++i) {
        int z;
        cin >> z;
        int ans = 1;
        int m1 = m;
        int k = 0;
        while (m % 2 == 0) {
            m /= 2;
            ++k;
        }
        ans *= get2(z, k);
        for (int p = 3; p * p <= m; ++p) {
            if (m % p == 0) {
                m /= p;
                ans *= getp(z, p);
                while (m % p == 0) {
                    m /= p;
                    ans *= p;
                }
            }
        }
        if (m != 1) {
            ans *= getp(z, m);
        }
        m = m1;
        cout << ans << " ";
    }
    cout << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3 3
0 1 2

output:

1 4 4 

result:

ok 3 number(s): "1 4 4"

Test #2:

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

input:

4 4
0 1 2 3

output:

4 8 4 0 

result:

ok 4 number(s): "4 8 4 0"

Test #3:

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

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 17ms
memory: 3632kb

input:

735134400 100000
4 4 1 2 3 4 4 4 5 4 3 4 1 1 1 1 2 0 1 4 4 5 4 1 0 0 1 3 0 4 0 5 3 0 3 0 5 4 0 0 3 2 5 3 2 4 3 4 2 1 3 3 2 2 2 3 1 0 1 2 3 4 3 5 4 4 0 1 5 2 2 3 3 2 4 3 5 5 1 3 1 1 4 3 4 3 4 5 2 4 1 3 2 0 5 0 0 5 5 1 2 0 3 4 0 4 1 0 1 4 5 5 3 1 3 0 3 5 0 4 2 0 4 0 0 0 4 0 2 2 2 4 5 3 0 2 0 4 1 4 1 2...

output:

1698693120 1698693120 1698693120 1698693120 0 1698693120 1698693120 1698693120 3822059520 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 21384000 1698693120 1698693120 1698693120 3822059520 1698693120 1698693120 21384000 21384000 1698693120 0 21384000 1698693120 21384...

result:

wrong answer 9th numbers differ - expected: '3397386240', found: '3822059520'