//求n!中有多少个质因子p
//时间复杂度O(nlogn)
int cal1(int n, int p)
{
int ans = 0;
for (int i = 2; i <= n; i++)
{
int temp = i;
while (temp % p == 0)
{
ans++;
temp /= p;
}
}
return ans;
}
//递推
int cal2(int n,int p)
{
int ans = 0;
while (n)
{
ans += n / p;
n /= p;
}
return ans;
}
06-07
1412
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-17
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交