HDU5673 Robot 默慈金数
分析:
注:然后学了一发线性筛逆元的姿势
链接:http://blog.miskcoo.com/2014/09/linear-find-all-invert
#include<iostream> #include<algorithm> #include<set> #include<vector> #include<queue> #include<cstdlib> #include<cstdio> #include<cstring> #include<cmath> using namespace std; typedef long long LL; typedef unsigned long long ULL; const int N=1e6+5; const LL mod=1e9+7; LL f[N],inv[N]; int main(){ inv[1]=1; for(int i=2;i<N;++i) inv[i]=inv[mod%i]*(mod-mod/i)%mod; f[0]=1; f[1]=1; for(int i=2;i<=N-5;++i) f[i]=((2*i+1)*f[i-1]%mod+(3*i-3)*f[i-2]%mod)%mod*inv[i+2]%mod; int T,n; scanf("%d",&T); while(T--){ scanf("%d",&n); printf("%I64d\n",f[n]); } return 0; }