getting wrong answer for Dragon Scroll

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

inline int get_int()
{
	int n=0;
	char c=0;
	while(c<33)
		c=getchar_unlocked();
	while(c>='0'&&c<='9')
	{
		n=(n<<3)+(n<<1)+(c-'0');
		c=getchar_unlocked();
	}
	return n;
}
int main(int argc, char const *argv[])
{
	int t,n,a,b,number,totalones,i,quint;
	int chambernoa,chambernob, oneina,oneinb,logproblem1,logproblem2;
	scanf("%d", &t);
	while(t--)
	{
		number=0;
		n=get_int();
		a=get_int();
		b=get_int();
		if (a==0)
			chambernoa=1;
		else
			chambernoa=log2(a)+1;
		if (b==0)
			chambernob=1;
		else
			chambernob=log2(b)+1;
		logproblem1=log2(pow(2,chambernoa)-a);
		logproblem2=log2(pow(2,chambernob)-b);
		oneina=chambernoa-logproblem1;
		oneinb=chambernob-logproblem2;
		if ((oneinb+oneina)>n)
			totalones=(2*n)-oneina-oneinb;
		else
			totalones=oneina+oneinb;
		
		if (totalones>0)
			number=pow(2,--n);
		for (i=1;i<totalones;i++)
			number+=pow(2,--n);
		printf("%d\n", number);
	}
	return 0;
}

You are not calculating the total number of ones in the numbers “a” and “b” correctly. Have a look at this. It is the accepted version of your code.

1 Like

that was a great solution… and thank you…
can I know in what test cases my logic fails.
PS: it passed in the given test cases.

In case of 7 your code says it has 2 no of ones.