You used int, so integer overflow
correct solution for your approach–> CodeChef: Practical coding for everyone