QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100 互動

#870. 黑客曼

统计

你,Hackerman 先生,已经获得了某个安全通讯应用服务器的访问权限。他们使用了一种基于分解三个大素数乘积的难度的新加密方法。

你阅读了源代码,并发现了他们实际生成这些数字的方式。他们定义了三个递推关系:

  • $x_n = (11 \cdot x_{n-1} + 7) \pmod{611\,953} \quad \forall n > 0$
  • $y_n = (13 \cdot y_{n-1} + 5) \pmod{746\,773} \quad \forall n > 0$
  • $z_n = (53 \cdot z_{n-1} + 3) \pmod{882\,389} \quad \forall n > 0$

种子 $x_0, y_0, z_0$ 似乎存储在一个安全文件中。

现在,他们为第 $k$ 个用户获取三个素数 $p_k, q_k, r_k$:

  • $p_k$ 是安全文件 X.axx 中的第 $x_k$ 个数字(所有数字都是不同的素数,且恰好有 31 位十进制数字)。
  • $q_k$ 是安全文件 Y.axx 中的第 $y_k$ 个数字(所有数字都是不同的素数,且恰好有 32 位十进制数字)。
  • $r_k$ 是安全文件 Z.axx 中的第 $z_k$ 个数字(所有数字都是不同的素数,且恰好有 33 位十进制数字)。

然后,他们计算公钥 $n_k = p_k \cdot q_k \cdot r_k$。

你拥有公钥数据库的临时访问权限,并且可以查询任意用户的最多 5 个公钥。

给定两个整数 $u$ 和 $v$。你需要拦截第 $u$ 个用户和第 $v$ 个用户之间的通讯。为了完成此任务,你需要计算 $p_u, q_u, r_u, p_v, q_v, r_v$;拥有这些值将使你能够完全操纵通讯。

为了简化输入/输出,我们要求你输出 $p_u + q_u + r_u + p_v + q_v + r_v$ 作为你的答案。

交互

首先,你必须读取一行包含两个整数 $u$ 和 $v$ ($0 \le u, v < 7 \cdot 10^{12}$)。

要询问第 $k$ 个用户的公钥 ($n_k$),请打印 “? $k$”,其中 $k$ 是用户索引。请记住,此类查询最多只能进行 5 次。

第一个用户的索引为 0,总共有 $7 \cdot 10^{12}$ 个用户,因此请确保在所有询问中 $0 \le k < 7 \cdot 10^{12}$。

当你计算出解后,打印 “! $a$”,其中 $a = p_u + q_u + r_u + p_v + q_v + r_v$。请记住,在此查询后停止你的程序会更安全。

打印每一行后,别忘了刷新输出!

文件 X.axxY.axxZ.axx 在整个问题中保持不变。

样例

输入 1

10 20
192279309409462992645482090330404758368400469722499925076043266903464961794187094077107243967491
274848544065337166381629952590164863776020394941410553373502453263042134278227621768923600557617
61991716112162091571854380103197141133071202062437636592434396525428433284775254050695414158203

输出 1

? 10
? 20
? 3
! 1188670725123074098790368447122696

说明

样例的解($u = 10$ 且 $v = 20$):

$p_{10} = 6745719728113484794920696767881$ $q_{10} = 54398126832702965410665141463513$ $r_{10} = 523986762172023700466774225430947$ $p_{20} = 6899037085323900149383957179569$ $q_{20} = 76607972465670150189802211467309$ $r_{20} = 520033106839239897778822214813477$ $p_{10} + q_{10} + r_{10} + p_{20} + q_{20} + r_{20} = 1188670725123074098790368447122696$

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.