QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 128 MB Puntuación total: 100

#3815. 弱伪随机数生成器

Estadísticas

Byteland 国土安全局正在努力打击恐怖分子。出现了一个新的恐怖组织,他们正在加密所有的通信。特工 Johnny 潜入了该组织,但在行动总部与他失去所有联系之前,他只设法发送了一条消息。情报如下:每个组织成员都有自己的加密密钥,该密钥使用线性伪随机数生成器生成。对于给定的参数 $p, x_0, a, b$,它生成序列 $f_0 = x_0, f_{i+1} = (a \cdot f_i + b) \pmod p$。组织首领使用密钥 $f_i$,第 $i$ 个成员使用密钥 $f_i$。一旦成为成员,就无法离开该组织。

在消息中,Johnny 还发送了生成器的参数以及他自己的密钥 $x$。国土安全局现在正试图破译截获的通信。你被赋予了一个略有不同的任务:试着找出该组织可能有多少名成员,也就是说,找到任意一个 $k$ 使得 $f_k = x$。该组织对候选人的筛选非常严格(现在更是如此,因为他们可能已经知道了 Johnny 的真实身份),所以可以肯定他们在 Johnny 之后没有招募任何人。

输入格式

输入的第一行也是唯一一行包含五个由空格分隔的整数:$p, x_0, a, b, x$ ($2 \le p < 10^9$, $p$ 为质数, $0 \le x_0, a, b, x < p$)。前四个数字是生成器的参数,最后一个是特工 Johnny 的密钥。

输出格式

在输出的第一行也是唯一一行中,打印一个满足 $f_k = x$ 且 $0 \le k \le 10^{18}$ 的数字 $k$,如果不存在这样的 $k$,则输出单词 NIE。如果存在多个这样的 $k$,你可以打印其中任意一个。

样例

样例输入 1

5 3 2 1 0

样例输出 1

2

生成的序列为 $3, 2, 0, 1, 3, 2, 0, 1, 3, 2, 0, 1, \dots$ 特别地,$f_2 = 0$。

样例输入 2

7 1 2 0 5

样例输出 2

NIE

生成的序列为 $1, 2, 4, 1, 2, 4, 1, 2, 4, \dots$ 没有密钥的值为 $5$,也许组织早就知道 Johnny 是双重间谍了?

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.