Can anyone help me why this is giving wa while my logic is correct

plzz help me in this qn …I don’t know why this is giving wa …

with my solution

@alwayswin - would suggest you to try once with the doubt solvers given the difficulty rating of this problem - CodeChef

1 Like

did you read the editorial already? TWONUMBERS - Editorial

I don’t know all errors in your code but I found 1 looking over it:

int a =n/2;
int b =n/2 +1;
cout<<(a * b * 1ll) -1;

a <= 10⁹
b <= 10⁹
a * b <= 10¹⁸

The associativity of * is left-to-right, meaning a * b * 1ll == (a * b) * 1ll

you multiplying 2 ints will cause the result to be an int, which obviously can cause an Integer Overflow. Only after you caused that Integer Overflow will you multiply with a long.

1 Like

Thanx bro i got my mistake

I am unable to find any doubt solver using your link