4.14 | 学习笔记

“双阶乘的质因数个数”

之前想要开数组,把所有1到10000的双阶乘值都存好,然后再写一个函数算出质因子个数,最后悲剧了

换个思路,每个因数中分别有多少个质因数m,相加就好啦

#include<bits/stdc++.h>
using namespace std;
int T,n,m,tmp,cnt;
int main()
{
    cin>>T;
    for(int i=0;i<T;++i)
    {
        cnt=0;
        cin>>n>>m;
        for(int j=n%2;j<=n;j+=2)
        {
            tmp=j;
            while(tmp&&tmp%m==0)++cnt,tmp/=m;
        }
        cout<<"case #"<<i<<":\n"<<cnt<<endl;
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/MissCold/p/10707463.html
今日推荐