The Wall (medium)
Heidi the Cow is aghast:cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks in the right chapter:
How to build a wall:
- Take a set of bricks.
- Select one of the possible wall designs. Computing the number of possible designs is left as a exercise to the reader.
- Place bricks on top of all other, according to the chosen design.
This seems easy enough. But Heidi was a Coding Cow, not a constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to n Bricks.
A wall is a set of wall segments as defined on the easy version. How many different walls can is constructed such that the wall consists of in least 1 and at most n Brick S? Walls is different if there exist a column c and a row R such that one wall have a brick in This is spot, and the other does not.
Along with N, you'll be a given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo6 + 3.
Input
The first line contains space-separated integers n and C, 1≤ n ≤500000, 1≤ C ≤200000.
Output
Print the number of different walls that Heidi could build, modulo 6 + 3.
Examplesinput
5 1
Output
5
Input
2 2
Output
5
Input
3 2
Output
9
Input
11 5
Output
4367
Input
37 63
Output
230574
Note
The number 6 + 3 is prime.
In the second sample case, the five walls is:
b B
B.. b, BB, B., and. B
In the third sample case, the nine walls is the five as in the second of the sample case and in addition the following four:
b B
b b b b
B.. B, BB, and BB
Analysis: Ball box Model (partition method) + multiplication inverse element; attention burst int;
Code:
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<ext/rope>#defineRep (I,m,n) for (i=m;i<=n;i++)#defineRSP (It,s) for (Set<int>::iterator It=s.begin (); It!=s.end (); it++)#defineVI vector<int>#definePII pair<int,int>#defineINF 0x3f3f3f3f#definePB Push_back#defineMP Make_pair#defineFi first#defineSe Second#definell Long Long#definePi ACOs (-1.0)Const intmaxn=7e5+Ten;Const intmod=1e6+3;Const intdis[4][2]={{0,1},{-1,0},{0,-1},{1,0}};using namespacestd;using namespace__gnu_cxx;ll gcd (ll p,ll q) {returnq==0? P:GCD (q,p%q);} ll Qpow (ll p,ll q) {ll F=1; while(q) {if(q&1) f=f*p%mod;p=p*p%mod;q>>=1;}returnF;}intn,m,ans,fac[maxn]={1};voidinit () { for(intI=1; i<=maxn-Ten; i++) fac[i]=1ll*i*fac[i-1]%MoD;}intInvintp) { returnQpow (p,mod-2);}intCintXinty) { return1LL*FAC[X]*INV (Fac[y])%MOD*INV (fac[x-y])%MoD;}intMain () {inti,j,k,t; scanf ("%d%d",&n,&m); Init (); Rep (I,m,n+m-1) ans= (Ans+c (i,m-1))%MoD; printf ("%d\n", ans); //System ("pause"); return 0;}
The Wall (medium)