Facto sum i dont know why i am getting 3 wrong test cases

question
https://hack.codingblocks.com/contests/c/512/56

my code
https://ide.codingblocks.com/s/34858

Actually the recursive method of finding factorial is very inefficient as its complexity is O(2^n)

Hence recursive method of computing factorial will not work for numbers as big as 1000

Try to find factorial by DP. That would make the program much more efficient…

You can even compute and store factorial of 1000 numbers and store it in array of size 1000
And then just use element at index to compute answer

Also use the formula
(a+b)%n = ( (a%n) + (b%n) ) % n

This would also make the program more efficient…

why this is more efficient

and how to use dynamic programming in this
please show me by editting my code

i am still getting 4 wrong cases
my code;
https://ide.codingblocks.com/s/33091
please help asap

please answer fast …