2018 Multi-University Training Contest 10 hdu 6432 Problem G. Cyclic(oeis题)

版权声明:哈哈哈哈哈哈哈哈哈哈哈哦吼~~ https://blog.csdn.net/threeh20/article/details/82026146

http://acm.hdu.edu.cn/showproblem.php?pid=6432

oeis 了解一下!

https://oeis.org/A000757

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
const int mod=998244353;
//a(n) = (n-2) * a(n-1) + (n-1) * a(n-2) - (-1)^n,

ll a[maxn];
int main()
{
    a[0]=1LL;
    a[1]=0;
    for(int i=2;i<=100000;i++)
    {
        if(i&1)
        {
            a[i]=((i-2)*a[i-1]%mod+(i-1)*a[i-2]%mod+1)%mod;
        }
        else a[i]=((i-2)*a[i-1]%mod+(i-1)*a[i-2]%mod-1+mod)%mod;
    }
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        printf("%lld\n",a[n]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/threeh20/article/details/82026146