QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 512 MB Total points: 100

#12627. Hawawshi 解密

Statistics

Hawawshi 是埃及的一种传统美食,人们非常珍视它,并将其存放在高度安全的保险柜中。这些保险柜由一个伪随机数生成器加密,该生成器根据以下方程生成随机数序列:$R_{n+1} = (a \cdot R_n + b) \pmod p$,其中 $a, b$ 和 $p$ 是整数,$p$ 是一个素数,$R_0$ 是第一个生成的数字,也称为序列的种子。

你收到了一些秘密信息,得知随机生成器的种子是从区间 $[A, B]$(包含边界)中随机选择的一个整数。此外,Hawawshi 保险柜的密钥是一个出现在前 $N$ 个生成的随机数(即 $R_0, R_1, \dots, R_{N-1}$)中的数字。你打算尝试一些不同的密钥 $X$,但首先,你需要知道 $X$ 出现在前 $N$ 个生成的随机数中的概率是多少?

输入格式

输入的第一行包含一个整数 $T$,表示测试用例的数量。 每个测试用例由一行组成,包含七个整数 $N, X, A, B, a, b$ 和 $p$。 $(1 \le N, X, A, B, a, b \le p - 1, 1 < p < 10^8, 1 \le A \le B \le \min(100, p - 1))$,其中 $p$ 是一个素数。

输出格式

对于每个测试用例,打印一行包含一个最简分数 $q/r$($q, r$ 为整数),表示数字 $X$ 出现在前 $N$ 个生成的随机数(由给定的伪随机数生成器生成)中的概率。保证该概率可以表示为所要求的最简分数。

样例

输入 1

5
2 2 4 5 2 1 7
6 3 4 5 2 1 7
2 2 1 5 2 1 7
4 5 5 5 4 7 11
4 6 5 5 4 7 11

输出 1

1/2
0/1
2/5
1/1
0/1

说明

作为伪随机数生成器的演示,如果 $a = 2, b = 1, p = 7, R_0 = 2$,则生成的数字序列为 $2, 5, 4, 2, 5, 4, 2, 5, 4, \dots$。 在最后两个测试用例中,$a = 4, b = 7, p = 11, R_0 = 5$,因此生成的序列为 $5, 5, 5, \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.