i want to get factorial of a number as large number as 10^6 with modulo 10^9+7.
i also have the test case with t upto 10^5 and factorial of a number n upto 10^6 with a time limit of 1s.
This brute force isn't helping me
I've never done this, but I believe the trick here is to avoid BigNum-type libraries by always keeping the computation within (or just above) 10^9 + 7.
iotaa, are you saying that your math is correct, but just too slow? If so, I think you need an algorithm that takes advantage of the special properties when mod'ing something by a prime number.
Sorry, I don't actually know the exact way to solve it. But I can almost guarantee there's a more efficient way than your method. You could google it and cheat... but what's the fun in that?