mam ye code test case pass kyu nahi kar raha hai
#include
#include
#include<math.h>
using namespace std;
int c[1000];
int l;
int d;
void test(int i,int n)
{
int p=1;
int sum=0;
int d=i;
int count=0;
while(i!=0)
{
int x=i&1;
i=i>>1;
int e=xp;
{
if(x==1)
{
sum=sum+e;
count++;
}
}
p=p2;
}
if(sum==n)
{
cout<<count;
}
}
int main()
{
int m;
cin>>m;
for(int j=0;j<m;j++)
{
int n;
cin>>n;
int x=pow(2,n);
int a[1000];
for(int i=0;i<x;i++)
{
test(i,n);
}
}
}
Incredible hulk
hi @YASHMATHURIA123 if you see the pattern, hulk can jump only in powers of 2. What else is formed by powers of 2? the binary representation of a number. Try to find a relation through that, then it will become really easy.
Mam maine ushe ko apply karke banaaya tha upar wala code
Two possiblity lekha har ek stair ki 0 and 1
@YASHMATHURIA123 actually, the relation is between the number of set bits in the binary representation of a number. Set bits are bits which are set to 1. You can find the number of set bits in a number with the function __builtin_popcount(int)
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.