Positive AND CodeChef Solution

Positive AND CodeChef Solution

In this post, the Positive AND CodeChef Solution is given. Question details : October Challenge 2020 Division 2 > Positive AND.

Positive AND CodeChef Solution

#include<bits/stdc++.h>
using namespace std;
const int MOD=1000000007;
#define ll long long
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
int main()
{
Fastio;
ll t; cin>>t;
while(t--)
{
ll n,i,j; cin>>n;
vector<ll> v;
if(n==1)
cout<<1<<endl;
if(n==2)
cout<<-1<<endl;
if(n==3)
cout<<2<<" "<<3<<" "<<1<<endl;
if(n==4)
cout<<-1<<endl;
if(n>=5)
{            
if(ceil(log2(n)) == floor(log2(n)))
cout<<-1<<endl;
else
{
v.pb(2);
v.pb(3);
v.pb(1);
for(i=4;i<=n;i++)
{
if(ceil(log2(i)) == floor(log2(i)))
{
v.pb(i+1);
v.pb(i);
i++;
}
else
v.pb(i);
}
for(j=0;j<v.size();j++)
cout<<v[j]<<" ";
cout<<endl;
}
}
}
}



The solution of the above program is contributed by Vishal Vaibhab (IIT BHU). If you like TheCode11, then do follow us on Facebook, Twitter and Instagram.

Previous Post Next Post

Contact Form