#722 (Div. 1) B. Kavi on Pairing Duty(DP)

题目描述

Kavi has 2n points lying on the OX axis, i-th of which is located at x=i.
Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows:
Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if for every 2 different segments A and B among those, at least one of the following holds:
One of the segments A and B lies completely inside the other.
A and B have the same length.
Consider the following example:
在这里插入图片描述
A is a good pairing since the red segment lies completely inside the blue segment.
B is a good pairing since the red and the blue segment have the same length.
C is not a good pairing since none of the red or blue segments lies inside the other, neither do they have the same size.
Kavi is interested in the number of good pairings, so he wants you to find it for him. As the result can be large, find this number modulo 998244353.
Two pairings are called different, if some two points are in one pair in some pairing and in different pairs in another.

Input

The single line of the input contains a single integer n (1≤n≤106).

Output

Print the number of good pairings modulo 998244353.

Examples

input
1
output
1
input
2
output
3
input
3
output
6
input
100
output
688750769

Note

The good pairings for the second example are:
在这里插入图片描述
In the third example, the good pairings are:
在这里插入图片描述

题目大意

有一条直线,上面有2*n个点。对于每对个点对A和B,要满足(下面两条中的一条):
1、A完全包含B或者B完全包含A
2、A和B的长度相等

题目分析

设:f[i]为点数为2*i的方案数
假 设 第 一 个 区 间 的 左 端 点 为 1 , 右 端 点 为 x 。 我 们 可 以 来 分 类 讨 论 : 假设第一个区间的左端点为1,右端点为x。我们可以来分类讨论: 1x
1 、 x > n 时 1、x>n时 1x>n
x = n + 1 , 第 一 个 区 间 外 的 点 数 为 y = n − 1 , 这 些 点 只 能 选 择 条 件 2 , 连 完 这 n − 1 个 点 之 后 , 剩 余 点 数 为 0 , x=n+1,第一个区间外的点数为y=n-1,这些点只能选择条件2,连完这n-1个点之后,剩余点数为0, x=n+1y=n12n10 这 部 分 的 方 案 数 为 f [ 0 ] 这部分的方案数为f[0] f[0]
x = n + 2 , y = n − 2 , 这 些 点 只 能 选 择 条 件 2 , 连 完 这 n − 2 个 点 之 后 , 剩 余 点 数 为 2 , 这 部 分 的 方 案 数 为 f [ 1 ] x=n+2,y=n-2,这些点只能选择条件2,连完这n-2个点之后,剩余点数为2,这部分的方案数为f[1] x=n+2y=n22n22f[1]
… … ……
x = 2 n , 第 一 个 区 间 外 的 点 数 为 y = 0 , 连 完 这 0 个 点 之 后 , 剩 余 点 数 为 2 ∗ n − 2 , 这 部 分 的 方 案 数 为 f [ n − 1 ] x=2n,第一个区间外的点数为y=0,连完这0个点之后,剩余点数为2*n-2,这部分的方案数为f[n-1] x=2ny=002n2f[n1]
我 们 可 以 发 现 , 这 种 情 况 的 答 案 为 ∑ i = 0 n − 1 f [ i ] 我们可以发现,这种情况的答案为\displaystyle\sum_{i=0}^{n-1} f[i] i=0n1f[i]

2 、 x < = n 时 2、x<=n时 2x<=n
当 连 接 1 和 x 后 , 中 间 有 x − 2 个 空 位 , 我 们 将 这 x − 2 个 点 连 接 之 后 , 这 一 块 的 长 度 就 是 x + x − 2 。 也 就 是 说 , 2 ∗ n 必 须 要 能 整 除 2 ∗ ( x − 1 ) 才 有 解 。 当连接1和x后,中间有x-2个空位,我们将这x-2个点连接之后,这一块的长度就是x+x-2。也就是说,2*n必须要能整除2*(x-1) 才有解。 1xx2x2x+x22n2(x1)
所 以 , 这 种 情 况 的 答 案 为 : n 因 子 的 个 数 d [ n ] 。 所以,这种情况的答案为:n因子的个数d[n]。 nd[n]

综 上 , d p 的 递 推 式 为 : f [ i ] = ∑ j = 0 i − 1 f [ j ] + d [ i ] 。 综上,dp的递推式为:f[i]=\displaystyle\sum_{j=0}^{i-1} f[j]+d[i]。 dpf[i]=j=0i1f[j]+d[i]

代码如下
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <iomanip>
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define PDD pair<double,double>
#define x first
#define y second
using namespace std;
const int N=1e6+5,mod=998244353;
int f[N],s[N],d[N];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)				//枚举所有因子i
		for(int j=i;j<=n;j+=i)			//枚举所有i的倍数
			d[j]++;
	
	f[1]=s[1]=1;						//f[]表示方案数,s[]表示f[]的前缀和
	for(int i=2;i<=n;i++)
	{
		f[i]=((LL)s[i-1]+d[i])%mod;
		s[i]=((LL)s[i-1]+f[i])%mod;
	}
	cout<<f[n]<<endl;
	return 0;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lwz_159

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值