QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#245502 | #6728. To the Park | gzzz | WA | 2ms | 6372kb | C++20 | 1.3kb | 2023-11-09 23:28:44 | 2023-11-09 23:28:44 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+10;
int vis[maxn];
bool done[maxn];
vector<int> e[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int> zhi;
for(int i=2;i<=1e5;i++){
if(!vis[i]) {
zhi.push_back(i);
}
for(int j=0;j<zhi.size()&&i*zhi[j]<=1e5;j++){
vis[i*zhi[j]]=zhi[j];
if(i%zhi[j]==0) {
break;
}
}
}
int t;cin>>t;
while(t--){
int n;cin>>n;
for(int i=1;i<=n;i++){
e[i].clear();
done[i]=false;
}
int fr=0;
for(int i=1;i<=n;i++){
int tmp=i;
while(vis[tmp]) {
int now=vis[tmp];
fr=max(fr,now);
e[now].push_back(i);
while(tmp%now==0) {
tmp/=now;
}
}
if(tmp!=1) {
e[tmp].push_back(i);
fr=max(fr,tmp);
}
}
vector<pair<int,int> >ans;
for(int i=1;i<=fr;i++){
stack<int> s;
int len=e[i].size();
for(int j=len-1;j>=0;j--){
if(!done[e[i][j]]) {
if(s.empty()){
s.push(e[i][j]);
}
else {
ans.push_back(pair<int,int>(s.top(),e[i][j]));
done[s.top()]=true;
done[e[i][j]]=true;
s.pop();
}
}
}
}
cout<<ans.size()<<" ";
for(int i=0;i<ans.size();i++){
cout<<ans[i].first<<" "<<ans[i].second<<" ";
}
cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 6372kb
input:
3 1 4 6
output:
0 1 4 2 1 6 4
result:
wrong answer Case #3: Participant has a worse answer