# BZOJ 3028 食物 (生成函数+数学题)

$f(x)=\frac{x}{(1-x)^{4}}=x(\frac{1}{(1-x)})^{4}$

 1 #include <cmath>
2 #include <cstdio>
3 #include <cstring>
4 #include <algorithm>
5 #define ll long long
6 #define dd double
7 #define N1 1010
8 using namespace std;
9
10 const int mod=10007;
11
12 int gint()
13 {
14     int ret=0,fh=1; char c=getchar();
15     while(c<'0'||c>'9'){if(c=='-')fh=-1;c=getchar();}
16     while(c>='0'&&c<='9'){ret=ret*10+c-'0';c=getchar();}
17     return ret*fh;
18 }
19
20 void exgcd(ll a,ll b,ll &x,ll &y)
21 {
22     if(!b){ x=1; y=0; return; }
23     exgcd(b,a%b,x,y); ll t=x; x=y; y=t-a/b*y;
24 }
25 char str[N1];
26 int a[N1],n;
27
28 int main()
29 {
30     scanf("%s",str+1);
31     int ret=0,i; n=strlen(str+1);
32     for(i=1;i<=n;i++) ret=(ret*10+str[i]-'0')%mod;
33     ll inv,invy; ret=1ll*(ret+2)*(ret+1)%mod*(ret)%mod;
34     exgcd(2,mod,inv,invy); inv=(inv%mod+mod)%mod; ret=1ll*ret*inv%mod;
35     exgcd(3,mod,inv,invy); inv=(inv%mod+mod)%mod; ret=1ll*ret*inv%mod;
36     printf("%d\n",ret);
37     return 0;
38 }

posted @ 2019-01-27 12:59  guapisolo  阅读(188)  评论(0编辑  收藏  举报