3185. 双阶乘的质因数个数

10165101131

include

include

int main()
{
int N,M;
int i,j;
int m,count,k;
scanf(“%d”,&N);
for(M=0;M<N;M++){
scanf(“%d%d”,&i,&j);
count=0;
if(i%2==0){//偶数
for(m=2;m<=i;m+=2){
k=m;
while(k%j==0){
count++;
k=k/j;
}
}
}
else{//奇数
for(m=1;m<=i;m+=2){
k=m;
while(k%j==0){
count++;
k=k/j;
}
}
}
printf(“case #%d:\n”,M);
printf(“%d\n”,count);
}

}

lnu_cxn

include

using namespace std;
int main() {
int t,count=0;
cin >> t;
while (t–) {
int n, m;
cin >> n >> m;
int ans = 0;
for(int i=1;i<=n;i++)
if (i % 2 == n % 2) {
int temp = i;
while (temp)
if (temp % m == 0) {
ans++;
temp /= m;
}
else
break;
}
cout << “case #” << count++ << “:\n”;
cout << ans << endl;
}
return 0;
}

10165102300

错了很多次,请指教
没错吧

wty24601

include

int zyzs(int a,int b){
int s = 0;
while(a % b == 0){
s += 1;
a /= b;
}
return s;
}
int main(){
int T;
scanf(“%d”,&T);
for (int i = 0 ; i < T ; i += 1){
int sum = 0;
printf(“case #%d:\n”,i);
int n , m ;
scanf(“%d%d”,&n,&m);
if (n % 2 == 1){
for (int j = 1 ; j <= n ; j += 2){
sum = sum + zyzs(j,m);
}
}else{
for ( int j = 2 ; j <= n ; j += 2 ){
sum = sum + zyzs(j,m);
}
}
printf(“%d\n”,sum);
}
}

10175102262 LarsPendragon

乘是没用的,只会导致数据溢出。判断双阶乘的每一项是否有对应因子即可。

你当前正在回复 博客/题目
存在问题!