Your logic is correct. Just use long int or long long instead of int for n and sum as contraints are till 10^9. It should give AC then.
You might search your doubt on the forum before posting straightaway.
Your logic is correct. Just use long int or long long instead of int for n and sum as contraints are till 10^9. It should give AC then.
You might search your doubt on the forum before posting straightaway.