Blazing goIITian
I think its based on Wilson's theorem or can be done using it.I am trying..I am a beginner in number theory.