Enter P N to find out how many of the n+1 lines of the Yang Hui triangle cannot be divisible by P
Lucas theorem:
A, B is a non-negative integer and P is a prime number. AB is written in P-system: a=a[n]a[n-1]...a[0],b=b[n]b[n-1]...b[0].
The combined number C (A, B) and C (A[n],b[n]) *c (a[n-1],b[n-1]) *...*c (a[0],b[0]) mod p congruence
namely: Lucas (n,m,p) =c (n%p,m%p) *lucas (n/p,m/p,p), in existence I. B[i]>a[i], the MoD value is 0, so it must be evenly divisible. When for all I,b[i]<=a[i]. A[i]!%p!=0, so must not divide evenly
#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 theorem