# "Open the Dragon Scroll" in easy section: need help, getting wrong answer!

#include
#include<math.h>
#include
using namespace std;

``````    int main()
{
int t;
scanf("%d", &t);

while(t--)
{
int n, a, b, count = 0, count1 = 0;
scanf("%d%d%d", &n, &a, &b);

int p[n], q[n];

//finding the binary of given decimals.
for(int i = n; i > 0; i--)
{
if(a >= 0)
{
p[i] = a % 2;
if(p[i] == 1)
count++;
a = a / 2;
}

if(b >= 0)
{
q[i] = b % 2;
if(q[i] == 1)
count1++;
b = b / 2;
}
}
//z is the number of 1's in the binary of two decimals together
int z = count + count1;

for(int i = 1; i <= n; i++)
p[i] = 0;

int i = 2;
while(z > n)
z = z - i;

for(i = 1; i <= z; i++)
p[i] = 1;

//converting the final answer from binary to decimal
int sum = 0, j;
for(i = n - 1,j = 1; i >= 0, j <= n; i--, j++)
sum = sum + (p[j]*pow(2, i));
printf("%d\n", sum);
}

return 0;
}``````

First of all, I think there will be an integer overflow as youâ€™ve declared a, b as `int` while the problem statement mentions `1 <= N <= 30, 0 <= A,B < 2^N`. So at max, A or B <= 2^30 = 1073741824 ~ 10^9. See?

@nisargshah well ya i see it. but other than that, is my implementation to my approach correct? its giving me wrong answer still, considering the mistake that you have pointed out. help!