There is an infinitely large rectangle, initially when you are in the upper left corner (i.e. the first row of the first column), each time you can select a lower right lattice, and teleport past (such as the red lattice from which can be directly teleport to the blue lattice), the firstN N Row mcolumn of the lattice there are several options, the answer to 10000000071000000007 modulo.
Input multiple sets of test data.
Two integersn,m(2≤n,m≤100000) n,m (2≤n,m≤100000)
Output An integer representing the answer to the sample Input
4 5
Sample Output
10
Lucas will understand that the number of m in the nth row of the Yang Hui Triangle Yang Hui triangle can be expressed as C (n-1,m-1)
Lucas theorem is used to find the value of C (n,m) mod p,p as a prime number, which is useful to solve large combinatorial numbers. The largest data processing power is p around 10^5.
C (n,m) = C (n-1,m-1) + C (n-1,m).
#include <iostream> #include <cstdio> #include <cstring>using namespace std; #define LL Long Longconst ll mod=1000000007; #define MAXN 70LL Pow (ll a,ll n,ll MoD) { ll base=a,ret=1; while (n) { if (n&1) ret= (ret*base)%mod; Base= (base*base)%mod; n>>=1; } return ret%mod;} ll C (ll n,ll k,ll p) { if (k==n) return 1; if (n-k<k) k=n-k; ll Ans=1; for (ll i=1;i<=k;i++) { ans=ans* (n-i+1)%p*pow (i,mod-2,p)%p; } return ans;} ll Lucas (ll n,ll M,ll p) { if (m==0) return 1; Return C (n%p,m%p,p) *lucas (n/p,m/p,p)%p;} int main () { ll n,m; while (~SCANF ("%lld%lld", &n,&m)) { Cout<<lucas (m+n-4,m-2,mod) <<endl; }}
Hdu_5698_ instantaneous movement