//Code Goes below:
#include <bits/stdc++.h>
using namespace std;
char check(unsigned long long int ,unsigned long long int);
//To replace character
/*I have made a recursive approach to categories in section Sn-1 or
'a' or replace(reverse(Sn-1)*/
char repla(char x)
{
if(x=='a')
return 'c';
else
return 'a';
}
//Recursive Function for check the category
char check(unsigned long long int k,unsigned long long int n)
{
if(k==1||n==1)
{
return 'a';
}
if(k<pow(2,n-1))
{
return(check(k,n-1));
}
else if(k==pow(2,n-1))
{
return 'a';
}
else
{
//here we are swaping the indexes
k=pow(2,n)-k+pow(2,n-1);
return(repla(check(k-pow(2,n-1),n-1)));
}
}
//Drive Code
int main()
{
unsigned long long int t,k,n;
char pp;
cin>>t;
while(t>0)
{
t--;
cin>>k;
n=ceil((log2(k)))+1;
pp=check(k,n);
cout<<pp<<endl;
}
return 0;
}
please find the faults in code whether I am printing wrong or the method is incorrect; I also got similar output with brute-force approach Time Complexity won't play much part; Thanks for considering and helping
Aucun commentaire:
Enregistrer un commentaire