QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#485270 | #4931. Comic Binge | PetroTarnavskyi# | WA | 0ms | 3860kb | C++20 | 1.5kb | 2024-07-20 15:46:38 | 2024-07-20 15:46:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 998244353;
int mult(int a, int b)
{
return (LL)a * b % mod;
}
int binpow(int a, int n)
{
int res = 1;
while (n)
{
if (n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
int f(int c)
{
int pw = 2 % c;
int k = 1;
while (pw % c != 1 % c)
{
pw = (2 * pw) % c;
k++;
}
return k;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
VI p(n);
for (int& pi : p)
{
cin >> pi;
pi--;
}
VI used(n);
int maxOrd = 0;
VI alpha(n + 1);
FOR(i, 0, n)
{
if (used[i])
continue;
int c = 0;
for (int v = i; !used[v]; v = p[v])
{
used[v] = 1;
c++;
}
int ord2 = 0;
while (c % 2 == 0)
{
c /= 2;
ord2++;
}
maxOrd = max(maxOrd, ord2);
int fc = f(c);
for (int j = 2; j <= fc; j++)
{
if (fc % j == 0)
{
int cur = 0;
while (fc % j == 0)
{
fc /= j;
cur++;
}
alpha[j] = max(alpha[j], cur);
}
}
}
int ans = 1;
FOR(i, 2, n + 1)
{
ans = mult(ans, binpow(i, alpha[i]));
}
ans = (ans + maxOrd) % mod;
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3860kb
input:
6 3 1 1 1 1 2 1 5 3 3 7 4
output:
2
result:
wrong answer 1st lines differ - expected: '13', found: '2'