hdu-5698 instantaneous movement (number theory + fast power)

Source: Internet
Author: User

Topic Links:

Move instantly problem Description

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 firstnN rows of M-m columns have several schemes, the answer to the 1000000007 modulo .

Input

Multiple sets of test data.

Two integers n,m (2<= n,m<=100000)

Output

An integer representing the answer

Sample Input
4 5
Sample Output
10

Test instructions



Ideas:

With the number of options that can only go down and to the right, the final result is that one is the same combination, with the fast power and Fermat theorem;

AC code :
#include <bits/stdc++.h>/*#include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring > #include <algorithm> #include <cstdio>*/using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=2e5+ -;intn,m; LL dp[2*N];intInit () {dp[1]=1;  for(intI=2;i<2*n;i++) {Dp[i]=dp[i-1]*(LL) i; Dp[i]%=MoD; }}ll Fastpow (ll X,ll y) {ll ans=1,Base=x;  while(y) {if(y&1) {ans*=Base; Ans%=MoD; }        Base*=Base; Base%=MoD; Y>>=1; }    returnans;}intMain () {Init ();  while(SCANF ("%d%d", &n,&m)! =EOF) {           if(n==2|| m==2) cout<<"1"<<"\ n"; Else{n-=2; M-=2; LL x=dp[n],y=Dp[m]; LL ans=dp[n+m]*fastpow (x*y%mod,mod-2)%MoD; cout<<ans<<"\ n"; }       }    return 0;}




hdu-5698 instantaneous movement (number theory + fast power)

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.