“双阶乘的质因数个数”
之前想要开数组,把所有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; }