Link for Direct series::: https://www.codechef.com/LOCMAY18/problems/DSERIES

can anyone please explain logic in O(T) complexity . I have made the logic that is of O(N) but i’m getting TLE in sub task 2. My logic was to sol the equation (T+1)!/1! + (T+2)!/2! +(T+3)!/3! +………+ (T+N)!/N!

How to apply Distribution Property of Mod on Division…because we can’t distribute it as like Multiplication. i mean (a/b)%1000000007 may or may not equal to (a%1000000007)/(b%1000000007). Thanks.