https://ide.codingblocks.com/s/37157
https://hack.codingblocks.com/contests/c/512/56
not all test cases are passed
please guide/help
https://ide.codingblocks.com/s/37157
https://hack.codingblocks.com/contests/c/512/56
not all test cases are passed
please guide/help
This solution has very poor efficiency as you are calculating the factorial many times.
Instead a better approach is that you can make an array of 1000 size and store factorial of a number on its index simply using
fact[i] = fact[i-1]*i
Then you can just access the factorial from index and compute the answer.
While storing in array, remember to take mode with 107, and then only store the value in array.
Take mod with 107 at each step…