large factorial with mod

i am practicing question https://www.codechef.com/problems/HAR001, i get WA and when i check others answer i realized that during factorial, it use %(mod-1) instead of %mod, as per image https://imgur.com/a/HrA818o
What are the reason behind it?

1 Like