Meaningless Operations Codeforces Solution

Meaningless Operations Codeforces Solution

In this post, the Meaningless Operations Codeforces Solution is given. Question details : Codeforces Global Round 1, problem: (C) Meaningless Operations.

Meaningless Operations Codeforces Solution

#include<bits/stdc++.h>
#define ll long long
#define fastio ios_base::sync_with(false); cin.tie(0);cout.tie(0);
const int MOD = 1000000007;
#define PI = acos(-1)
using namespace std ;
int a[106];
bool isprime(ll n)
{
if( n <=1)
{
return 0;
}
for(int i = 2 ; i*i <= n ; i++)
{
if(n%i ==0)
return 0;
}
return 1 ;
}
int main()
{
int t ; cin >> t ;
while(t--)
{
ll n ; cin >> n ;
if(n%2==0)
{
ll c = 1 ;
while(n >= c)
{
c*=2;
}
cout << c-1 << endl;
}
else 
{
ll chk = n+1 ;
if((chk & (chk-1))== 0)
{
if(isprime(n) || n ==1)
cout << 1 << endl;
else 
{
for(int i = 3 ; i*i<= n ; i++)
{
if(n%i==0)
{
cout << n/i << endl;
break;
}
}
}
}
else 
{
ll z = 1 ;
while( z < n)
{
z*=2;
}
cout << z-1 << endl;
}
}
}
}

Meaningless Operations Codeforces Solution by Vishal Vaibhab (IIT BHU). If you like TheCode11, then do follow us on Facebook, Twitter and Instagram.

Post a Comment

Previous Post Next Post

Contact Form