Given n,m,p means that <=m beans are placed on n trees, how many schemes are there, total proposal mod p
If you place the M beans on n trees, you can use the Insert plate method
Get program number is C (n+m-1,n-1)
So the number of programs that put 0<=i<=m beans on n Trees is C (n+i-1,n-1)
That
where C (n,k) =c (n-1,k) +c (n-1,k-1) is the meaning of extracting k from the n number of combinations, then for a number, it is either not taken, to C (n-1,k), or to C (n-1,k-1)
1#include <stdio.h>2#include <string.h>3#include <stdlib.h>4#include <algorithm>5#include <iostream>6#include <queue>7#include <stack>8#include <vector>9#include <map>Ten#include <Set> One#include <string> A#include <math.h> - using namespacestd; - #pragmaWarning (disable:4996) thetypedefLong LongLL; - Const intINF =1<< -; - /* - + */ - +LL fact[100001]; A at ll Pow (ll A, LL K, ll P) - { -LL ret =1; - while(k) - { - if(K &1) inRET = ret * A%p; -A = a * a%p; toK >>=1; + } - returnret; the } * ll C (ll N, ll M, ll P) $ {Panax Notoginseng if(N < m | | m <0)return 0; -LL a = Fact[n], b = fact[n-m] * Fact[m]%p; the returnA * POW (b, P-2, p)%p; + } ALL Lucas (intNintMintp) the { + if(M = =0)return 1; - returnC (n%p, m%p,p) * Lucas (n/p, m/p, p)%p; $ } $ intMain () - { - intt, N, M, p; thescanf"%d", &t); - while(t--)Wuyi { thescanf"%d%d%d", &n, &m, &p); -fact[0] =1; Wu for(inti =1; I <= p; ++i) -Fact[i] = fact[i-1] * I%p; Aboutprintf"%i64d\n", Lucas (n +m, n, p)); $ - } - return 0; -}
hdu3037 (Lucas theorem)