列表

详情


NC214892. TheJourneyofGeorAutumn

描述

Once upon a time, there was a witch named Geor Autumn, who set off on a journey across the world. Along the way, she would meet all kinds of people, from a country full of ICPC competitors to a horse in love with dota---but with each meeting, Geor would become a small part of their story, and her own world would get a little bit bigger.

Geor just arrived at the state of Shu where people love poems. A poem is a permutation of . ( is a permutation of means that each is an integer in and that are distinct.) One poem is good if for all integer satisfying and , . Here denotes the minimum value among .

Help Geor calculate how many good poems there are, given and . To avoid huge numbers, output the answer modulo .

输入描述

The first line contains two integers n and k separated by a single space (, ).

输出描述

Output only one integer in one line---the number of good poems modulo .

示例1

输入:

1 1

输出:

1

示例2

输入:

2 3

输出:

2

示例3

输入:

3 2

输出:

4

示例4

输入:

4 2

输出:

10

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 392ms, 内存消耗: 156920K, 提交时间: 2021-01-26 16:47:19

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=998244353;
const int maxn=1e7+10;
ll inv[maxn],p[maxn];
int n,k;
int main(){
	inv[1]=1;
	for(int i=2;i<maxn;i++)
	inv[i]=mod-mod/i*inv[mod%i]%mod;
	scanf("%d%d",&n,&k);
	ll s=p[0]=1;
	for(int i=1;i<=n;i++){
		p[i]=inv[i]*s%mod;
		s+=p[i];
		if(i>=k) s-=p[i-k];
		s%=mod;
	}
	ll ans=p[n]%mod+mod;
	for(int i=1;i<=n;i++)
	ans=ans*i%mod;
	printf("%lld",ans);
}

上一题