https://www.codechef.com/problems/MODINV01/

For this problem while i was executing for indefinite times ,its giving SIGSTP runtime error while when submitted its still accepting!
PS: I know the iteration count must be less than divisor but i want to do indefinte iterations and handle the exception ,how could i do that?