Logic for direct series asked in locMay 2018

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.

See this has already been covered see my ans https://discuss.codechef.com/questions/128490/didnt-understand-the-2-lines-of-the-code-in-dseries-authors-solution?page=1#128519