You are given a number N.
Print its factorial under modulo 1000000007.
Example:
Input: n = 5
Output: 120
Approach
C++
#include <bits/stdc++.h>using namespace std;#define MOD 1000000007long long dp[100001];void fact(){dp[0] = 1;dp[1] = 1;for (long long i = 2; i <= 100000; i++)dp[i] = ((i) % MOD * (dp[i - 1]) % MOD) % MOD;}int main(){long long n = 5;fact();long long ans = dp[n];cout << ans << "\n";return 0;}
No comments:
Post a Comment