An issue in the input range

In the prblm magic pairs prblmCode : ALEXNUMB it is given that the value of n will be in the range 1n100000 and if we try to code this in java then range of int is -2,147,483,648 … 2,147,483,647 but still it gives wrong answer until we dont take dataype of n as long ??

you might be using some operation on int which leads to long.

1 Like

When A = 9999999 and B = 9999999, and you write if (A*B < 20), the A*B will be calculated in an int datatype. And hence you’ll have overflows. So you’ll have to take care of intermediate calculations too. One way to avoid this is do 1LL * A * B, or just initialise A and B as long long.

1 Like

Got it brother , you were right !!!