Wrong Answer
Code
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
int gcd(int a, int b)
{
while(b!=0)
{
int temp = b;
b = a%b;
a = temp;
}
return a;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
vector<int>v;
int cntg=0;
for(int i=N; i>=1; i--)
{
v.push_back(i);
}
for(int i=0; i<N; i++)
{
for(int i=0; i<N-1; i++)
{
if(gcd(v[i],v[i+1])==1 && v[i]-v[i-1]>1)
{
cntg++;
}
}
if(cntg==N)
{
for(int i=0; i<v.size(); i++)
{
cout<<v[i]<<" ";
}
cout<<endl;
}
else next_permutation(v.begin(), v.end());
}
cout<<-1<<endl;
v.clear();
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1203 D. Roy Loves Permutation
- Contest
- Brain Booster #10
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-06-13 17:37:43
- Judged At
- 2025-06-13 17:37:43
- Judged By
- Score
- 0
- Total Time
- 13ms
- Peak Memory
- 540.0 KiB