QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#574791 | #3799. It's Surely Complex | BongoCatEnjoyer# | WA | 1ms | 3876kb | C++20 | 3.1kb | 2024-09-19 00:35:51 | 2024-09-19 00:35:51 |
Judging History
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 && i != j && (a[i] > 0 && a[j] > 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: 100
Accepted
time: 1ms
memory: 3580kb
input:
2 1
output:
1 1
result:
ok single line: '1 1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
2 2
output:
1 1
result:
ok single line: '1 1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
2 3
output:
0 0
result:
ok single line: '0 0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
2 4
output:
0 0
result:
ok single line: '0 0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
3 1
output:
2 1
result:
ok single line: '2 1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
3 2
output:
2 0
result:
ok single line: '2 0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 3
output:
1 0
result:
ok single line: '1 0'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 4
output:
1 1
result:
ok single line: '1 1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 5
output:
1 0
result:
ok single line: '1 0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
3 6
output:
1 0
result:
ok single line: '1 0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 1
output:
4 1
result:
ok single line: '4 1'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
5 2
output:
0 0
result:
ok single line: '0 0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
5 3
output:
0 0
result:
ok single line: '0 0'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 4
output:
0 0
result:
ok single line: '0 0'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
5 5
output:
0 0
result:
ok single line: '0 0'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
5 6
output:
0 0
result:
ok single line: '0 0'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
5 7
output:
0 0
result:
ok single line: '0 0'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 8
output:
0 0
result:
ok single line: '0 0'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 9
output:
0 0
result:
ok single line: '0 0'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 10
output:
0 0
result:
ok single line: '0 0'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
7 1
output:
6 1
result:
ok single line: '6 1'
Test #22:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
7 2
output:
3 0
result:
ok single line: '3 0'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
7 3
output:
2 5
result:
ok single line: '2 5'
Test #24:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
7 4
output:
1 0
result:
ok single line: '1 0'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
7 5
output:
5 2
result:
ok single line: '5 2'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
7 6
output:
6 0
result:
ok single line: '6 0'
Test #27:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
7 7
output:
1 0
result:
ok single line: '1 0'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
7 8
output:
4 4
result:
ok single line: '4 4'
Test #29:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
7 9
output:
1 0
result:
wrong answer 1st lines differ - expected: '4 0', found: '1 0'