QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137676 | #6728. To the Park | Yarema# | WA | 63ms | 5776kb | C++17 | 1.2kb | 2023-08-10 16:29:11 | 2023-08-10 16:29:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 100447;
int d[N];
VI pr;
bool used[N];
int find(int x)
{
if (pr[x] || x == 1) return -1;
if (!used[d[x]])
return d[x];
x /= d[x];
if (!used[x]) return x;
return find(x);
}
void solve()
{
int n;
cin >> n;
vector<PII> ans;
RFOR (i, n + 1, 1)
{
if (pr[i] || used[i]) continue;
int y = find(i);
if (y != -1)
ans.PB({i, y});
}
cout << SZ(ans);
FOR (i, 0, SZ(ans)) cout << ' ' << ans[i].F << ' ' << ans[i].S;
cout << '\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
pr.assign(N, 1);
FOR (i, 2, N)
{
if (pr[i])
{
d[i] = i;
for (int j = i * 2; j < N; j += i)
{
d[j] = i;
pr[j] = 0;
}
}
}
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3928kb
input:
3 1 4 6
output:
0 1 4 2 2 6 3 4 2
result:
ok 4 cases
Test #2:
score: -100
Wrong Answer
time: 63ms
memory: 5776kb
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 3 8 2 6 3 4 2 4 9 3 8 2 6 3 4 2 5 10 5 9 3 8 2 6 3 4 2 5 10 5 9 3 8 2 6 3 4 2 6 12 3 10 5 9 3 8 2 6 3 4 2 6 12 3 10 5 9 3 8 2 6 3 4 2 7 14 7 12 3 10 5 9 3 8 2 6 3 4 2 8 15 5 14 7 12 3 10 5 9 3 8 2 6 3 4 2 9 16 2 15 5 14 7 12 3 10 5 9 3 8 2 6 3 4 2 9 16 2 15 5 14...
result:
wrong answer Case #8: Duplicate person 2