QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#181158 | #7225. The Kirakira Cycle | ucup-team288# | WA | 1ms | 5892kb | C++20 | 1.8kb | 2023-09-16 16:05:54 | 2023-09-16 16:05:54 |
Judging History
answer
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
using i64 = long long;
constexpr int N = 51000000;
int f[N + 1], minp[N + 1], pos[N + 1];
vector<int> primes;
void chmax(auto &a, auto b) { a = max(a, b); }
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 2; i <= n * (n - 1) / 2; i++) {
if (!minp[i]) {
primes.push_back(i);
minp[i] = i;
}
for (int p : primes) {
if (p > n * (n - 1) / 2 / i) {
break;
}
minp[p * i] = p;
if (i % p == 0) {
break;
}
}
}
for (int i = 1; i <= n; i++) {
f[i] = -i;
}
for (auto p : primes) {
for (int i = 1; p * i <= n * (n - 1) / 2; i++) {
f[p * i] += f[i];
}
}
f[1] += n;
for (int i = 2; i <= n * (n - 1) / 2; i++) {
f[i] += f[i - 1];
f[i] += n;
}
int ans = 0;
ll m = n * (n-1) / 2;
vector<int> vis_t(m+1, -1);
ll ret = 0;
//for (int i = 1;i <= m;++i) DE(i, f[i]);
for (int i = 0;i <= m;++i) {
if (vis_t[i] != -1) continue;
ll ct = 0;
for (int x = i;;x = f[x]) {
//DE(x, vis_t[x], ct);
if (vis_t[x] != -1) {
if (vis_t[x] < ct) {
chmax(ret, ct - vis_t[x]);
break;
}
}
vis_t[x] = ct++;
}
}
cout << ret << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
input:
2
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5592kb
input:
10
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5892kb
input:
43
output:
7
result:
ok 1 number(s): "7"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5672kb
input:
3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 1ms
memory: 5832kb
input:
4
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 1ms
memory: 5596kb
input:
5
output:
2
result:
ok 1 number(s): "2"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5884kb
input:
6
output:
2
result:
ok 1 number(s): "2"
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 5684kb
input:
7
output:
3
result:
wrong answer 1st numbers differ - expected: '1', found: '3'