# what is wrong in following code (byte to bit)

#include
#include<math.h>
using namespace std;
int main()
{
int N,t,byte=0,bit=1,nab=0;
cin>>t;
cout<<endl;
int arr[t];

``````for(int i=0;i<t;i++)
cin>>arr[i];

int rem,a;
for(int i=0;i<t;i++)
{

rem=arr[i]%26;
a=(arr[i]-rem)/26;

bit=pow(2,a);
if(rem>2 && rem<=10)
{	nab=bit;
bit=0;}
else if(rem>10 && rem<26)
{
byte=bit;
bit=0;
}
cout<<bit<<" "<<nab<<" "<<byte<<" "<<endl;
bit=1;nab=0;byte=0;
``````

}
return 0;

}

@kishahn111r

Your logic behind the question is absolutely perfect. I have no doubt in that. But your code will not work on some tricky test cases. In the test cases in which n(according to the question) will be divisible by 26, your code will not work.

For example:

1

26

Your code will give an output as follows if I am not wrong:

2 0 0

But the desired output should be:

0 0 1

This is because the byte has not changed into two bits. When n is divisible by 26, it should remain the same answer and the answer will change when (n % 26 == 1).

In the question, it is written that byte will change int two bits AFTER 16ms after it has occured. When it is as the 26th ms, it will be byte’s 16th ms, and after that it will change. Therefore, it will change between the 26th and 27th ms.

I hope this was some help to you:)