QOJ.ac

QOJ

Límite de tiempo: 3.0 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#17265. 忘了加油

Estadísticas

Fizz Buzz City 是一个大型城市,因此它拥有一条环形公路来帮助市民在各个区域之间出行也就不足为奇了。这条道路是环形的,既可以顺时针通行,也可以逆时针通行。环形公路的总长度恰好为 $\ell$ 公里,并且其上有 $\ell$ 个路口。路口的设置使得沿道路相邻两个路口之间的距离恰好为 1 公里。

一天,Fiodar 正在环形公路上驾车行驶,突然想起需要给汽车加油。不幸的是,他错过了驶向加油站的转弯!当然,由于交通规则的限制,他不能直接掉头往回开。于是,他在错过转弯后立即停下车,心想:“好吧,我就沿着环形公路朝同一个方向一直开到下一个加油站。但如果太远了怎么办?”

Fiodar 刚来到 Fizz Buzz City,所以他不知道加油站的具体位置。但他知道环形公路上总共有 $n$ 个加油站。他还知道加油站只设在路口处,且任意两个加油站不会位于同一个路口。

“我想知道,为了确保能遇到至少一个加油站,我最多需要行驶多远的距离?考虑到我不知道加油站是如何分布的,如果每种分布方案的概率均等,那么在平均情况下,这个最大距离是多少?”Fiodar 心想。

你能帮他回答这个问题吗?请计算他为了遇到至少一个加油站而必须行驶的最大距离的期望值(无论他当前身处何处以及朝哪个方向行驶)。假设所有合法的加油站分布方案都是等概率出现的。

输入格式

唯一的一行包含两个整数 $\ell$ 和 $n$($2 \le n \le \ell \le 10^6$),分别表示环形公路的长度(单位:公里)和加油站的数量。

输出格式

输出一个整数:所求的最大距离期望值模 $998\,244\,353$ 的结果。

形式化地,令 $M = 998\,244\,353$。可以证明,答案可以表示为最简分数 $\frac{p}{q}$,其中 $p$ 和 $q$ 是整数且 $q \not\equiv 0 \pmod M$。输出等于 $p \cdot q^{-1} \bmod M$ 的整数。换句话说,输出一个满足 $0 \le x < M$ 且 $x \cdot q \equiv p \pmod M$ 的整数 $x$。

样例

输入样例 1

2 2

输出样例 1

1

输入样例 2

5 3

输出样例 2

499122179

输入样例 3

20 5

输出样例 3

796329095

说明

在第一个样例中,无论加油站如何分布,从道路上任意一点到加油站的最大距离都是 1。

在第二个样例中,有 5 种分布方案的相邻距离为 $(1, 2, 2)$(最大值为 2),以及 5 种分布方案的相邻距离为 $(1, 1, 3)$(最大值为 3)。因此,分数值答案为 $\frac{5\cdot2+5\cdot3}{5+5} = \frac{5}{2}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.