n * n Squares, draw a line from top left to bottom right. A robot moves from top to bottom to the right and can only go right or down. and ask only on the line above or below to walk, cannot cross this line, how many different way? Because the number of methods can be large, you only need to output mod 10007 results.
Input
Enter a number n (2 <= n <= 10^9).
Output
The number of output methods Mod 10007.
Input Example
4
Output Example
10
Obviously a Cattleya number, launched ans = C (2*n-2,n-1) * 2/n% MOD
First let n--, ans = C (2*n,n) * 2/(n+1)% MOD so the formula looks good.
Since n <= 10^9, but MOD = 10007, it is necessary to use the Lucas theorem for Ans
//File Name:nod1120.cpp//Author:long//Mail: [email protected]//Created time:2016 May 27 Friday 15:46 58 seconds#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#defineLL Long Longusing namespacestd;Const intMOD =10007; LL Jie[mod]; ll QP (ll X,ll y) {ll res=1; while(y) {if(Y &1) Res = res * x%MOD; X= x * x%MOD; Y>>=1; } returnRes;}voidinit () {jie[0] =1; for(intI=1; i<mod;i++) Jie[i]= jie[i-1] * I%MOD;} LL Get_c (intXinty) { if(Y = =0|| y = = x)return 1; returnJIE[X] * QP (jie[y] * jie[x-y]% Mod,mod-2) %MOD;} ll Lucas (ll X,ll y) {ll ans=1; intu,v; while(X >0|| Y >0) {u= x%MOD; V= y%MOD; Ans= ans * get_c (u,v)%MOD; X/=MOD; Y/=MOD; } returnans;}intMain () {init (); intN; while(~SCANF ("%d",&N)) {N--; printf ("%d\n",(int) Lucas (2*n,n) * QP (n+1, mod-2) *2%MOD); } return 0;}
51nod 1120 Robot Walk Square V3 Cattleya number Lucas theorem