阶乘因式分解(一)

阶乘因式分解(一)

时间限制:3000 ms  |  内存限制:65535 KB
难度:2
 
描述

给定两个数m,n,其中m是一个素数。

将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m。

 
输入
第一行是一个整数s(0<s<=100),表示测试数据的组数
随后的s行, 每行有两个整数n,m。
输出
输出m的个数。
样例输入
2
100 5
16 2
样例输出
24
15

#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main(int argc, char* argv[])
{
int t;
cin>>t;
while(t--)
{
int n,m,i,b,count;
cin>>n>>m;
count=0;
for(i=2;i<=n;i++)
{
b=i;
while(b%m==0)
{
b=b/m;
count++;
}
}
cout<<count<<endl;
}
return 0;
}

posted on 2014-04-23 13:00  52Cyan  阅读(128)  评论(0编辑  收藏  举报

导航