I was solving the example problem of dynamic programming at HackerEarth (here)

```
#include <iostream>
#define MOD 1000000007
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
long long int t, n;
cin>>t;
long long int ans = 1;
while(t--){
ans = 1L;
cin>>n;
for(long long int i = 2;i<=n;i++){
ans = (ans*i)%MOD;
}
cout<<ans<<endl;
}
return 0;
}
```

Why is it giving me TLE?

Is my approach not of dynamic programming? I am saving my solution in just one variable “ans” as I don;t need more than that.