QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#133589 | #4937. Permutation Transformation | Team_name# | WA | 3ms | 3976kb | C++23 | 1.5kb | 2023-08-02 11:34:55 | 2023-08-02 11:34:57 |
Judging History
answer
#include <iostream>
#include <utility>
#include <vector>
using LL = long long;
constexpr int N = 1E5;
constexpr int mod = 998244353;
using VPII = std::vector<std::pair<int, int>>;
int P[N + 1]; bool vis[N + 1];
int alp[N + 1], beta[N + 1];
VPII factor(int n)
{
VPII PF;
for (int i = 2; i * i <= n; ++i)
if (!(n % i))
{
int a = 0;
do
++a, n /= i;
while (!(n % i));
PF.emplace_back(i, a);
}
if (n > 1)
PF.emplace_back(n, 1);
return PF;
}
void chk_max(int& a, int b) { if (a < b) a = b; }
int mul(int a, int b, int m) { return static_cast<LL>(a) * b % m; }
int pow(int b, int e, int m)
{
int r = 1;
while (e--) r = mul(r, b, m);
return r;
}
int main()
{
std::ios_base::sync_with_stdio(false), std::cin.tie(nullptr);
int N; std::cin >> N;
for (int i = 1; i <= N; ++i)
std::cin >> P[i];
for (int i = 1; i <= N; ++i)
{
if (vis[i]) continue;
int u = i, cnt = 0;
do
u = P[u], vis[u] = true, ++cnt;
while (u != i);
for (auto [u, v] : factor(cnt))
chk_max(alp[u], v);
}
for (int i = 1; i <= N; ++i)
{
if (!alp[i]) continue;
int pa = pow(i, alp[i], N + 1);
int phi = pa - pa / i;
// 2^phi = 1 mod pa
int d;
for (d = 1; d <= phi; ++d)
if (!(phi % d))
if (pow(2, d, pa) == 1)
break;
for (auto [u, v] : factor(d))
chk_max(beta[u], v);
}
int ans = 1;
for (int i = 1; i <= N; ++i)
ans = mul(ans, pow(i, beta[i], mod), mod);
std::cout << alp[2] + ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3580kb
input:
5 3 5 1 2 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3476kb
input:
8 7 5 1 6 8 2 3 4
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3504kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3968kb
input:
100000 20864 34918 58550 1465 75674 30743 27235 88900 47488 50029 46054 84871 20330 72228 16506 44561 92519 97750 82891 60324 90508 39290 24663 38077 90189 30671 95476 64027 70888 90749 22566 8525 33675 16635 23392 97636 35788 89625 41966 78051 94034 15407 26545 83799 2233 10873 56946 71566 19045 44...
output:
216333199
result:
ok single line: '216333199'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3540kb
input:
14040 5654 6009 6131 4703 11773 11998 4998 12737 10500 11016 6763 10135 13053 1667 12945 10168 12062 12329 9809 1172 13554 4227 5857 8597 5199 13041 1845 1612 2889 1556 4338 11927 7659 8409 1233 13034 1978 6832 13622 12056 3849 1006 3670 13140 6226 13735 3047 3349 3922 9715 3697 11902 5694 10537 357...
output:
49222142
result:
ok single line: '49222142'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3976kb
input:
100000 26099 31546 24098 31277 80935 49363 8360 60556 17826 1248 723 59192 78846 17804 39019 68536 43655 6565 55374 72670 15887 27291 34447 3203 35267 62706 97777 38681 7861 9528 46702 19753 37932 83370 55972 33504 97146 21259 18464 66690 85076 23713 83611 57447 37649 42026 44322 73961 50022 72220 3...
output:
193641155
result:
ok single line: '193641155'
Test #7:
score: -100
Wrong Answer
time: 3ms
memory: 3644kb
input:
31435 22209 2142 11768 29844 8545 24738 2619 18535 24922 6386 7527 2506 630 1332 27397 18293 7948 18880 17974 5081 31145 17802 2634 31359 25821 18891 14894 18756 29308 4403 5368 7876 19271 14440 4591 19794 7931 23123 9800 9418 29051 26687 12835 9250 23005 29500 6180 10587 27462 27646 8990 31408 1409...
output:
200737098
result:
wrong answer 1st lines differ - expected: '732408604', found: '200737098'