P1641-[SCOI2010]生成字符串

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef double db;
 5 #define INF 0x3f3f3f3f
 6 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 7 #define _rep(i,a,b) for(int i = (a);i > b;i --)
 8 #define mod 20100403
 9 
10 inline ll read()
11 {
12     ll ans = 0;
13     char ch = getchar(), last = ' ';
14     while(!isdigit(ch)) last = ch, ch = getchar();
15     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
16     if(last == '-') ans = -ans;
17     return ans;
18 }
19 inline void write(ll x)
20 {
21     if(x < 0) x = -x, putchar('-');
22     if(x >= 10) write(x / 10);
23     putchar(x % 10 + '0');
24 }
25 ll exgcd(ll a,ll b,ll &x,ll &y)
26 {
27     if(b==0)
28     {
29         x=1,y=0;
30         return a;
31     }
32     ll res=exgcd(b,a%b,y,x);
33     y-=a/b*x;
34     return res;
35 }
36 
37 ll Inv(ll a)
38 {
39     ll d,x,y;
40     d=exgcd(a,mod,x,y);
41     if(d==1)
42       return (x%mod+mod)%mod;
43     return -1;
44 } 
45 
46 ll C(ll n,ll m)
47 {
48     ll ans1=1,ans2=1;
49     for(int i=n,j=1;j<=m;j++,i--)
50     {
51         ans1=ans1*i%mod;
52         ans2=ans2*j%mod;
53     }
54     return (ll)(ans1*Inv(ans2)%mod);
55 } 
56 ll N,M;
57 int main()
58 {
59     N = read();
60     M = read();
61     ll a = C(N+M,M);
62     ll b = C(N+M,M-1);
63     printf("%lld\n",(a-b+mod)%mod);
64     return 0;
65 }

 

posted @ 2019-09-06 15:39  Asurudo  阅读(175)  评论(0编辑  收藏  举报