标签:io sp html amp bs htm as res ui
输入p n 求杨辉三角的第n+1行不能被p整除的数有多少个
Lucas定理:
A、B是非负整数,p是质数。AB写成p进制:A=a[n]a[n-1]...a[0],B=b[n]b[n-1]...b[0]。即:Lucas(n,m,p)=c(n%p,m%p)*Lucas(n/p,m/p,p),在存在i,b[i]>a[i]时,mod值为0,所以必定整除;当对于所有i,b[i]<=a[i]时,a[i]!%p!=0,所以必定不能整除
#include <cstdio> #include <cmath> #include <cstring> using namespace std; int main() { int p, n; int cas = 1; while(scanf("%d %d", &p, &n) != EOF) { if(p ==0 && n ==0) break; int sum = 1; while(n) { sum *= n%p+1; n /= p; } printf("Case %d: %04d\n", cas++, sum%10000); } }
HDU 3304 Interesting Yang Yui Triangle lucas定理
标签:io sp html amp bs htm as res ui
原文地址:http://blog.csdn.net/u011686226/article/details/39993089