Solution Link - CodeChef: Practical coding for everyone
you have taken every variable as int while constraint says n ans Pi go upto 10^9.
try changing variables to long long
In case you still need a tricky test case , here is one !
Thank you, brother. It is working now .