Problem
Solution
我们去构造各个物品的生成函数
f
1
(
x
)
=
1
1
−
x
2
f_1(x)=\frac {1} {1-x^2}
f1(x)=1−x21
f 2 ( x ) = 1 + x f_2(x)=1+x f2(x)=1+x
f 3 ( x ) = 1 + x + x 2 f_3(x)=1+x+x^2 f3(x)=1+x+x2
f 4 ( x ) = x 1 − x 2 f_4(x)=\frac {x} {1-x^2} f4(x)=1−x2x
f 5 ( x ) = 1 1 − x 4 f_5(x)=\frac {1} {1-x^4} f5(x)=1−x41
f 6 ( x ) = 1 + x + x 2 + x 3 = ( x + 1 ) ( x 2 + 1 ) f_6(x)=1+x+x^2+x^3=(x+1)(x^2+1) f6(x)=1+x+x2+x3=(x+1)(x2+1)
f 7 ( x ) = 1 + x f_7(x)=1+x f7(x)=1+x
f 8 ( x ) = 1 1 − x 3 f_8(x)=\frac {1} {1-x^3} f8(x)=1−x31
乘积为
x
(
1
−
x
)
−
4
x(1-x)^{-4}
x(1−x)−4
x ∑ i = 0 ∞ ( − 4 i ) ( − x ) i x\sum_{i=0}^\infty\binom {-4} i (-x)^{i} xi=0∑∞(i−4)(−x)i
第
n
n
n项系数就是求后面求和式子中的
n
−
1
n-1
n−1项,即
(
−
1
)
n
−
1
(
−
4
n
−
1
)
=
(
−
1
)
n
−
1
(
−
4
)
n
−
1
‾
(
n
−
1
)
!
(-1)^{n-1}\binom {-4} {n-1}=(-1)^{n-1}\frac {(-4)^{\underline {n-1}}} {(n-1)!}
(−1)n−1(n−1−4)=(−1)n−1(n−1)!(−4)n−1
我们对
n
−
1
n-1
n−1的奇偶性分类讨论,容易知道肯定是一个正数,那么直接去掉所有负号,再改一下上升幂的表现方法即可得到
(
4
n
−
1
‾
)
(
n
−
1
)
!
=
A
n
+
2
n
−
1
(
n
−
1
)
!
=
(
n
+
2
n
−
1
)
=
(
n
+
2
3
)
\frac {(4^{\overline{n-1}})} {(n-1)!}=\frac {A_{n+2}^{n-1}} {(n-1)!}=\binom {n+2} {n-1}=\binom {n+2} {3}
(n−1)!(4n−1)=(n−1)!An+2n−1=(n−1n+2)=(3n+2)
Code
#include <cstdio>
using namespace std;
typedef long long ll;
const int mod=10007,inv6=1668;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
x=0;int f=0;char ch=getchar();
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') f=1,ch=getchar();
while(ch>='0'&&ch<='9') x=(x*10+ch-'0')%mod,ch=getchar();
if(f) x=-x;
}
int n;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
read(n);
printf("%lld\n",(ll)n*(n+1)*(n+2)*inv6%mod);
return 0;
}