QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574786#3799. It's Surely ComplexBongoCatEnjoyer#WA 0ms3560kbC++203.1kb2024-09-19 00:33:282024-09-19 00:33:30

Judging History

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

  • [2024-09-19 00:33:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-09-19 00:33:28]
  • 提交

answer

#include <bits/stdc++.h>

#define ll                      long long
#define all(v)                  (v).begin(), (v).end()
#define forn(var, n)            for (ll (var) = 0; (var) < (n); ++(var))
#define forr(var, start, end)   for (ll (var) = (start); (var) < (end); ++(var))
#define fori(var, start, end)   for (ll (var) = (start); (var) > (end); --(var))
#define fora(var, obj)          for (auto (var) : (obj))
#define MOD1                    (ll) (1e9 + 7)
#define MOD9                    (ll) (998244353)
#define prints(x)               cout << (x) << " "
#define println(x)              cout << (x) << "\n"
#define newl()                  cout << "\n"

using namespace std;

ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

ll powmod(ll a, ll b, ll m) {
    ll res = 1;

    while (b) {
        if (b & 1) res = mod(res * a, m);
        a = mod(a * a, m);
        b >>= 1;
    }

    return mod(res, m);
}

void solve() {
    ll p, n; cin >> p >> n;

    vector<ll> a(p, n / p);
    forn(i, mod(n, p) + 1) a[i]++;
    // forn(i, min(10LL, p)) prints(a[i]); newl();

    vector<ll> b(p);
    forn(i, p) {
        forr(j, i, p) {
            if (i == 0 && j == 0) continue;

            ll is = mod(mod(i % p, p) * mod(i % p, p), p);
            ll js = mod(mod(j % p, p) * mod(j % p, p), p);

            if ((is + js) % p == 0 && (a[i] > 0 && b[i] > 0)) {
                prints(0); println(0); return;
            }

            // prints(i); prints(j); prints(is); println(js);

            if (i != j) b[(is + js) % p] = (b[(is + js) % p] % 8 + ((a[i] % 8) * (a[j] % 8)) % 8) % 8;
            else if (a[i] < 5) b[(is + js) % p] = (b[(is + js) % p] % 8 + (mod(a[i] * (a[i] - 1) / 2, 8))) % 8;
            else b[(is + js) % p] = (b[(is + js) % p] % 8 + (mod(mod(a[i], p) * (mod(a[i] - 1, p)) / 2, 8))) % 8;

            // println(b[(is + js) % p]);
        }
    }
    // forn(i, min(10LL, p)) prints(b[i]); newl();

    forn(i, p) a[i] = mod(a[i], p);

    ll magic1 = 1, cnt = 0;
    forn(i, p) {
        magic1 = (magic1 * powmod(i, b[i], p)) % p;
        cnt += 2 * b[i];
    }

    // prints(magic1); println(cnt);

    ll magic2 = 1, cnt2 = 0;
    forr(i, 1, p) {
        magic2 = mod(magic2 * powmod(i, a[i], p), p);
        cnt2 += a[i];
    }

    magic1 = mod(mod(magic1 * magic2, p) * powmod(2, cnt2 / 2, p), p);
    cnt += cnt2;

    // prints(magic1); println(cnt);

    if (cnt == 0) magic1 = 0;
    ll c = cnt % 8;
    pair<ll, ll> ans = {0, 0};

    if (c >= 1 && c <= 3) {
        ans.second = mod(magic1, p);
    } else if (c >= 5 && c <= 7) {
        ans.second = mod(-magic1, p);
    } else {
        ans.second = 0;
    }

    if (c <= 1 || c >= 7) {
        ans.first = mod(magic1, p);
    } else if (c >= 3 && c <= 5) {
        ans.first = mod(-magic1, p);
    } else {
        ans.first = 0;
    }

    prints(ans.first); println(ans.second);
    return;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    ll 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: 3560kb

input:

2 1

output:

0 0

result:

wrong answer 1st lines differ - expected: '1 1', found: '0 0'