题解 | #牛群全排列数#
牛群全排列数
https://www.nowcoder.com/practice/5ab233c23fcc4c69b81bd5a66c07041c
知识点:
递归/溢出
分析:
求一个阶乘,注意溢出即可。
编程语言:
C++
完整代码:
int mod = 1000000007; long long result = 1; long long dfs(int u){ if(u == 1) return 1; else{ long long res = 1; res = (dfs(u - 1) * u) % mod; return res; } } int factorial(int n) { return (int)dfs(n); }
int mod = 1000000007; int factorial(int n) { long long result = 1; for (int i = 2; i <= n; i++) { result = (result * i) % mod; } return (int)result; }