QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#695379 | #6728. To the Park | Shuishui | AC ✓ | 49ms | 5228kb | C++14 | 1.6kb | 2024-10-31 19:54:57 | 2024-10-31 19:54:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));
vector<int> p, pr;
int tot;
void sieve(int n) {
p.assign(n + 1, 0);
pr.clear();
for (int i = 2; i <= n; i++) {
if (!p[i]) p[i] = i, pr.push_back(i);
for (auto v : pr) {
if (i * v > n) break;
p[i * v] = v;
if (v == p[i]) break;
}
}
tot = (int)pr.size();
}
void solve(void)
{
int n;
cin >> n;
sieve(n);
vi vis(n + 2);
vector<array<int, 2>> ans;
reverse(all(pr));
auto match = [&](int x, int y)
{
vis[x] = vis[y] = 1;
ans.pb({x, y});
};
for (auto d : pr)
{
int p = 0;
vi v;
for (int i = d; i <= n; i += d)
if (!vis[i])
v.pb(i);
for (auto i : v)
if (!(i == d * 2 && Sz(v) & 1))
{
if (p)
{
match(i, p);
p = 0;
}
else
p = i;
}
}
int m = Sz(ans);
cout << m << " \n"[m == 0];
for (int i = 0; i < m; i++)
cout << ans[i][0] << " " << ans[i][1] << " \n"[i == m - 1];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
// cout << fixed << setprecision(10);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3680kb
input:
3 1 4 6
output:
0 1 4 2 2 6 3 4 2
result:
ok 4 cases
Test #2:
score: 0
Accepted
time: 49ms
memory: 5228kb
input:
1007 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
0 0 0 1 4 2 1 4 2 2 6 3 4 2 2 6 3 4 2 2 6 3 8 2 3 9 3 4 2 8 6 4 10 5 9 3 4 2 8 6 4 10 5 9 3 4 2 8 6 4 10 5 6 3 12 9 8 2 4 10 5 6 3 12 9 8 2 5 14 7 10 5 6 3 12 9 8 2 6 14 7 15 5 6 3 12 9 4 2 10 8 6 14 7 15 5 6 3 12 9 8 2 16 10 6 14 7 15 5 6 3 12 9 8 2 16 10 7 14 7 15 5 9 3 18 12 4 2 8 6 16 10 7 14 7 ...
result:
ok 1008 cases