C ++ soln using mathematical approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; void preComputeFact ( vector < long long int > & fact , int n ) { for ( int i = 1 ; i <= n ; i ++ ) fact . push_back ( fact [ i - 1 ] * i ) ; }