Please either format your code or link to your submission - the forum software has mangled it and it wonโt compile!
You have print Yes and No in new lines
You have missed endl there !
Thats it
Be careful
Thanks a lot!! It worked
Pls like my reply !
Welcome
Thanks a lot !
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(n10,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(n10,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;
}
โโโ