QOJ.ac

QOJ

実行時間制限: 10.0 s メモリ制限: 256 MB 満点: 100 インタラクティブ

#8216. 混乱的素数

統計

伟大的神谕者选择了一个 $1$ 到 $100$ 的均匀随机排列:$p_1, p_2, \dots, p_{100}$。

从神谕者那里获取信息的唯一方法是询问排列中一对数字 $p_a$ 和 $p_b$ ($a \neq b$) 的最大公约数 (gcd)。

找出所有质数和数字 $1$ 所在的位置,并报告它们。输出应该是一个位串,如果位置 $i$ 上的数字是质数或 $1$,则该位为 $1$,否则为 $0$。

你的程序运行一次,在此次运行中,它将被测试 $1000$ 个测试用例。请注意,每次提交时,测试用例都是新生成的。设 $S$ 为所有测试用例中使用的查询次数之和。为了通过测试,必须满足:$S \leq 1000 \times 600$。

交互

在每个测试用例中,你的程序可以立即开始进行查询。

为了找出 $p_a$ 和 $p_b$ 的 gcd,输出一行格式为 “? a b” 的内容,其中 $a$ 和 $b$ 是两个不同的整数,满足 $1 \leq a, b \leq 100$。之后,你应该读取一个整数 $g$。$g$ 将等于 $\gcd(p_a, p_b)$。

当你确定了所有质数和数字 $1$ 的位置后,打印一行格式为 “! answer” 的内容,其中 answer 是一个长度为 $100$ 的位串,如果 $p_j$ 是质数或数字 $1$,则在位置 $j$ 处为 $1$。当 $p_j$ 是合数时,位串在该位置应包含 $0$。这不计入总查询次数 $S$。

之后,该测试用例结束,你的程序应立即进入下一个测试用例,或者如果完成了所有 $1000$ 个测试,则停止。

不要忘记在每次查询后刷新输出。

样例

样例输入 1

1
2
2
3

样例输出 1

? 1 3
? 2 4
? 6 4
? 6 3
! 111010

说明

此样例不是一个有效的测试用例。仅作说明,此处 $p$ 是 $1$ 到 $6$ 的数字排列。随机排列恰好为 $p = [1, 2, 3, 4, 5, 6]$。

尽管通过查询获得的信息不足以找出质数的位置,但输出是正确的:一个长度为 $6$ 的位串,在位置 $1, 2, 3$ 和 $5$ 处为 $1$。$p_1, p_2, p_3$ 和 $p_5$ 包含质数和数字 $1$。

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.