This is because your implementation uses recursion. For small numbers it
works fine, but for large numbers it overflows the stack.
if(nr)return modulo(nr * fact(nr - 1));
nr stack frames. Since the stack space is very
limited, entering a large number causes stack overflows.
Change your implementation to use iterative calculation of the factorial
to avoid the crash.
Once you are done fixing the crash, deal with the numeric overflow.
Rather than computing the modulo after the factorial has been calculated,
keep applying modulo at each step of the calculation.