CKWLK - Editorial

Please either format your code or link to your submission - the forum software has mangled it and it wonโ€™t compile! :slight_smile:

1 Like

You have print Yes and No in new lines
You have missed endl there !
Thats it
Be careful

3 Likes

Thanks a lot!! It worked

Pls like my reply !
Welcome :slightly_smiling_face::smile:

Thanks a lot !

2 Likes

https://www.codechef.com/viewsolution/28422827
Please let me know where iโ€™m wrong

Consider the testcase:

1
40

//My approach

int c1;
int isPowerOfTwo(int n)
{
c1=0;
while (n != 1)
{

    n = n/2;  
    c1++;
}  
return c1;  

}

int main()
{
int t;
cin>>t;

while(tโ€“)
{
ll n;
cin>>n;
string s=to_string(n);
int p=-1;
for(int i=s.size()-1;i>=0;iโ€“)
{
if(s[i]!=โ€˜0โ€™)
{ p=i;
break;
}
}

ll sum=0;
ll a=0;
for(int i=0;i<=p;i++)
{
sum=10*sum+(s[i]-โ€˜0โ€™);
}
if(__builtin_popcount(sum)==1)
{
int h=isPowerOfTwo(sum);
if(s.size()-p>h)
cout<<โ€œYesโ€<<endl;
else
cout<<โ€œNoโ€<<endl;
}
else
{ int f=0;
while(n!=1)
{
if(n%10==0)
n/=10;
else if(n%10!=0)
{cout<<โ€œNoโ€<<endl;
f=1;break;}
}
if(f==0)cout<<โ€œYesโ€<<endl;
}
}
return 0;
}

Is this a problem of Dynamic Programming?

#include
#define ll long long
using namespace std;

bool check(ll int n,ll int lim)
{
if(n==lim)
{
return true;
}
if(n>lim)
{
return false;
}
bool a=check(n20,lim);
bool b=check(n
10,lim);
return a|b;
}
int main() {
// your code goes here
int t;
cin>>t;
while(tโ€“)
{
ll int n;
cin>>n;
if(check(1LL,n))
{
cout<<โ€œYesโ€<<endl;
}
else
{
cout<<โ€œNoโ€<<endl;
}
}
return 0;
}

,
#include
#define ll long long
using namespace std;

bool check(ll int n,ll int lim)
{
if(n==lim)
{
return true;
}
if(n>lim)
{
return false;
}
bool a=check(n20,lim);
bool b=check(n
10,lim);
return a|b;
}
int main() {
// your code goes here
int t;
cin>>t;
while(tโ€“)
{
ll int n;
cin>>n;
if(check(1LL,n))
{
cout<<โ€œYesโ€<<endl;
}
else
{
cout<<โ€œNoโ€<<endl;
}
}
return 0;
}
โ€˜โ€™โ€™