UVALive - 3700 Interesting Yang Hui Triangle

题目大意就是求一下 杨辉三角的第N行中不能被P整除的有多少个。

直接卢卡斯定理一下就行啦。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void W(int x,int y){ if(x>4) return; W(x+1,y/10),putchar(y%10+'0');}
int n,p,ans,m,C;
int main(){
	while(scanf("%d%d",&p,&n)==2&&p&&n){
		ans=1,m=n,C++;
		for(;m;m/=p) ans*=(m%p)+1;
		printf("Case %d: ",C);
		W(1,ans),puts("");
	}
	return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/JYYHH/p/8906318.html
今日推荐