算组合数中的素因子p的个数,基本同这题

http://www.cnblogs.com/autsky-jadek/p/6592194.html

#include<cstdio>
using namespace std;
typedef long long ll;
int calc(int n,int p){
	int res=0;
	ll t=p;
	while(t<=(ll)n){
		res+=(n/(int)t);
		t*=(ll)p;
	}
	return res;
}
int T,n,m;
int main(){
//	freopen("b.in","r",stdin);
	scanf("%d",&T);
	for(;T;--T){
		scanf("%d%d",&n,&m);
		printf("%d\n",calc(2*n,m)-2*calc(n,m));
	}
	return 0;
}

相关文章:

  • 2021-11-07
  • 2022-12-23
  • 2021-09-02
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2021-09-05
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2021-12-13
  • 2021-11-08
  • 2022-12-23
  • 2021-05-27
  • 2021-12-17
  • 2022-01-04
相关资源
相似解决方案