QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#10812. 仅仅是乘法逆元

统计

Yukikaze 正在学习数论。她发现了一个计算整数模素数 $p$ 的乘法逆元的神秘函数。该函数的伪代码如下:

1: function F(x, p)
2: if x ≤ 1 then
3: return 1
4: else
5: return −p/x · F(p mod x, p) mod p
6: end if
7: end function

她想知道,如果她以均匀分布在 $[1, p - 1]$ 范围内的随机整数调用此函数,函数调用的期望次数是多少。

输入格式

输入的第一行包含一个整数 $T$ ($1 \le T \le 100$),表示测试用例的数量。 接下来的 $T$ 行,每行包含一个整数 $p$ ($2 \le p \le 10^6$, $p$ 为素数),表示上述函数的参数。

输出格式

对于每个测试用例,输出一行答案。 如果你的答案的绝对误差或相对误差不超过 $10^{-6}$,则被视为正确。 形式化地,设你的答案为 $a$,标准答案为 $b$。如果满足 $\frac{|a-b|}{\max\{1,|b|\}} \le 10^{-6}$,则你的答案将被接受。

样例

输入 1

5
2
3
5
7
999983

输出 1

1.0000000000
1.5000000000
2.0000000000
2.1666666667
15.9864347558

说明

对于样例中的第 4 个测试用例,我们有:

$F(1, 7)$ $F(2, 7) \to F(1, 7)$ $F(3, 7) \to F(1, 7)$ $F(4, 7) \to F(3, 7) \to F(1, 7)$ $F(5, 7) \to F(2, 7) \to F(1, 7)$ $F(6, 7) \to F(1, 7)$

因此答案为 $(1 + 2 + 2 + 3 + 3 + 2)/6 = 2.16666666 \dots$。

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.