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.

image

no u have not given p in input.