Hdu_5698_ instantaneous movement

Source: Internet
Author: User
Tags pow

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.