Its giving TLE.Please check once
hello @gaganpreetsachdev1
ur r not giving p in input .
give p and it will work fine
also do p=p%n to keep value of p < n
I have given the input for p.Please check once properly.

no u have not given p in input.
hello @gaganpreetsachdev1
ur r not giving p in input .
give p and it will work fine
also do p=p%n to keep value of p < n
I have given the input for p.Please check once properly.

no u have not given p in input.