my logic is correct ,works properly for small numbers but I don’t what happens when input is 10^5…their is problem related to precision??
It is because of integer overflow, you have used int for storing n. Now, when answer(y) is calculated integer overflows.
y=((n+1)*(n+2))/2-1;
Solution : Just use long long for storing n. (or you can type cast n while calculating y )
1 Like
thank you for your support…