根據打表可得,對於n的情況

任意一個首位!=1的排列時,則其答案-1可以與首位為1的情況對應

當n=4時

排列 答案

1 2 3 4 ------ 0

1 2 4 3 ------ 1

1 3 2 4 ------ 1

1 3 4 2 ------ 2

1 4 2 3 ------ 2

1 4 3 2 ------ 1

2 1 3 4 ------ 1

2 1 4 3 ------ 2

2 3 1 4 ------ 2

2 3 4 1 ------ 3

2 4 1 3 ------ 3

2 4 3 1 ------ 2

3 1 2 4 ------ 2

3 1 4 2 ------ 3

3 2 1 4 ------ 1

3 2 4 1 ------ 2

3 4 1 2 ------ 2

3 4 2 1 ------ 3

4 1 2 3 ------ 3

4 1 3 2 ------ 2

4 2 1 3 ------ 2

4 2 3 1 ------ 1

4 3 1 2 ------ 3

4 3 2 1 ------ 2

記f[i]表示i個數,所有i個數可以組成的排列的答案總和

則我們發現,有(n-1)(n-1)!項首位不等於1的排列,對答案有1的貢獻

除此之外,我們會發現,首項為1的數由於有n個數(包括自己)與其對應

所以對答案有n
f[i-1]的貢獻

所以f[i]=if[i-1]+(i-1)(i-1)!

注意要逆元

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mo 998244353ll
ll t,f[10000010],n,jc[10000010];
ll qp(ll x,ll y){
	ll r=1;
	x%=mo;
	while(y){
		if(y&1)r=r*x%mo;
		y>>=1;
		x=(x*x)%mo;
	}
	return r;
}
int main(){
	freopen("inverse.in","r",stdin);
	freopen("inverse.out","w",stdout);
	jc[0]=1;
	for(ll i=1;i<=10000010;i++)
		jc[i]=jc[i-1ll]*i%mo;
	for(ll i=1;i<=10000010;i++)
		f[i]=(i*f[i-1ll]%mo+(i-1ll)*jc[i-1ll]%mo)%mo;
	scanf("%lld",&t);
	while(t--){
		scanf("%lld",&n);
		printf("%lld\n",f[n]*qp(jc[n],mo-2ll)%mo);
	}
}

jzoj5931的更多相关文章

随机推荐

  1. sublime Text与python3的中文编码错误解决办法

    在 linux服务器上运行代码报错: Python3中遇到UnicodeEncodeError: ‘ascii’ codec can’t encode characters in ordinal no ...

  2. 2017年值得一看的7个APP设计

    新媒体时代蓬勃发展,各类APP如雨后春笋般出现.下载到合适的APP,不仅衣食住行一键搞定,甚至健身.社交.阅读等需求也能足不出户地满足.对于广大“吃瓜群众”来说,选择APP是个人需求以及跟随潮流的选择 ...

  3. Directory /usr/local/hadoop/tmp/tmp/hadoop-root/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible

    解决方法: <property> <name>hadoop.tmp.dir</name> <value>/usr/local/hadoop/tmp< ...

  4. windows8.1 初体验

    昨天装了Win8.1,Office2013 由于是英文版的,需要装一下中文语言包,然后就能使用自带的微软拼音输入法了. 我喜欢双屏时的桌面背景,选择span时一张图片可以跨越2个屏幕,比win7的好. ...

  5. springboot问题,没有主清单属性

    在pom.xml中添加 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins< ...

  6. spring boot使用java读取配置文件,DateSource测试,BomCP测试,AnnotationConfigApplicationContext的DataSource注入

    一.配置注解读取配置文件         (1)@PropertySource可以指定读取的配置文件,通过@Value注解获取值   实例:           @PropertySource(val ...

  7. linux上安装jdk1.8

    开发环境centos7, jdk1.8 首先去官网下载jdk1.8的linux64位安装包 进入目录/usr/local/mypackage/java 利用winscp上传jdk安装包 命令tar - ...

  8. ORBSlam with ROS

    ...相机标定 calibration 基本就是做CV 的常识 ORBSlam源码:

  9. Ubuntu 14.04 LTC 有线网络--网线不识别,灯不亮问题

    sudo ethtool -s eth0 autoneg off speed 100 duplex full

  10. Icicle partition

    <!DOCTYPE html> <html> <head> <title>Icicle</title> <script type=&q ...