CF1091G.New Year and the Factorisation Collaboration
NOI/NOI+/CTSC
通过率:0%
时间限制:6.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Integer factorisation is hard. The RSA Factoring Challenge offered $$100\,000$ for factoring RSA-1024, a 1024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 1024-bit number.
Since your programming language of choice might not offer facilities for handling large integers, we will provide you with a very simple calculator.
To use this calculator, you can print queries on the standard output and retrieve the results from the standard input. The operations are as follows:
- + x y where x and y are integers between 0 and n−1. Returns (x+y)modn.
- - x y where x and y are integers between 0 and n−1. Returns (x−y)modn.
- * x y where x and y are integers between 0 and n−1. Returns (x⋅y)modn.
- / x y where x and y are integers between 0 and n−1 and y is coprime with n. Returns (x⋅y−1)modn where y−1 is multiplicative inverse of y modulo n. If y is not coprime with n, then −1 is returned instead.
- sqrt x where x is integer between 0 and n−1 coprime with n. Returns y such that y2modn=x. If there are multiple such integers, only one of them is returned. If there are none, −1 is returned instead.
- ^ x y where x and y are integers between 0 and n−1. Returns xymodn.
Find the factorisation of n that is a product of between 2 and 10 distinct prime numbers, all of form 4x+3 for some integer x.
Because of technical issues, we restrict number of requests to 100.
整数分解是困难的。RSA 分解挑战赛曾为分解 RSA-1024(一个由两个素数相乘得到的 1024 位整数)提供 100 000 美元奖金。截至目前,尚无人成功领取该奖金。本题要求你对一个 1024 位整数进行质因数分解。
由于你所选用的编程语言可能不支持大整数运算,我们将为你提供一个非常简单的计算器。
要使用该计算器,你可在标准输出上打印查询语句,并从标准输入读取结果。支持的运算如下:
+ x y:其中 x 和 y 是介于 0 与 n−1 之间的整数。返回 (x+y)modn。- x y:其中 x 和 y 是介于 0 与 n−1 之间的整数。返回 (x−y)modn。* x y:其中 x 和 y 是介于 0 与 n−1 之间的整数。返回 (x⋅y)modn。/ x y:其中 x 和 y 是介于 0 与 n−1 之间的整数,且 y 与 n 互质。返回 (x⋅y−1)modn,其中 y−1 是 y 模 n 的乘法逆元。若 y 与 n 不互质,则返回 −1。sqrt x:其中 x 是介于 0 与 n−1 之间且与 n 互质的整数。返回满足 y2modn=x 的整数 y。若存在多个这样的整数,则仅返回其中一个;若不存在,则返回 −1。^ x y:其中 x 和 y 是介于 0 与 n−1 之间的整数。返回 xymodn。
请对整数 n 进行质因数分解,其中 n 是 2 至 10 个互异素数的乘积,且每个素数均形如 4x+3(x 为某整数)。
由于技术限制,你最多只能发出 100 次请求。
输入格式
The only line contains a single integer n (21≤n≤21024). It is guaranteed that n is a product of between 2 and 10 distinct prime numbers, all of form 4x+3 for some integer x.
唯一一行包含一个整数 n(21≤n≤21024)。保证 n 是 2 到 10 个互异素数的乘积,且每个素数均具有 4x+3 的形式(其中 x 为某个整数)。
输出格式
You can print as many queries as you wish, adhering to the time limit (see the Interaction section for more details).
When you think you know the answer, output a single line of form ! k p_1 p_2 ... p_k, where k is the number of prime factors of n, and pi are the distinct prime factors. You may print the factors in any order.
Hacks input
For hacks, use the following format:.
The first should contain k (2≤k≤10) — the number of prime factors of n.
The second should contain k space separated integers p1,p2,…,pk (21≤n≤21024) — the prime factors of n. All prime factors have to be of form 4x+3 for some integer x. They all have to be distinct.
你可以输出任意数量的查询,只要满足时间限制(详见“交互”部分)。
当你认为自己已经得出答案时,请输出一行形如 ! k p_1 p_2 ... p_k 的答案,其中 k 是 n 的不同质因数的个数,pi 是 n 的所有不同质因数。质因数的输出顺序可以任意。
Hack 输入格式
对于 Hack,需使用如下格式:
第一行应包含 k(2≤k≤10)——即 n 的质因数个数。
第二行应包含 k 个以空格分隔的整数 p1,p2,…,pk(满足 21≤n≤21024)——即 n 的质因数。所有质因数均须形如 4x+3(其中 x 为某整数),且互不相同。
输入输出样例
输入#1
21 7 17 15 17 11 -1 15
输出#1
+ 12 16 - 6 10 * 8 15 / 5 4 sqrt 16 sqrt 5 ^ 6 12 ! 2 3 7
说明/提示
We start by reading the first line containing the integer n=21. Then, we ask for:
- (12+16)mod21=28mod21=7.
- (6−10)mod21=−4mod21=17.
- (8⋅15)mod21=120mod21=15.
- (5⋅4−1)mod21=(5⋅16)mod21=80mod21=17.
- Square root of 16. The answer is 11, as (11⋅11)mod21=121mod21=16. Note that the answer may as well be 10.
- Square root of 5. There is no x such that x2mod21=5, so the output is −1.
- (612)mod21=2176782336mod21=15.
We conclude that our calculator is working, stop fooling around and realise that 21=3⋅7.
我们首先读取第一行,其中包含整数 n=21。然后,我们依次计算:
- (12+16)mod21=28mod21=7。
- (6−10)mod21=−4mod21=17。
- (8⋅15)mod21=120mod21=15。
- (5⋅4−1)mod21=(5⋅16)mod21=80mod21=17。
- 16 的平方根。答案为 11,因为 (11⋅11)mod21=121mod21=16。注意:答案也可能是 10。
- 5 的平方根。不存在满足 x2mod21=5 的 x,因此输出 −1。
- (612)mod21=2176782336mod21=15。
我们由此确认计算器工作正常,停止胡闹,并意识到 21=3⋅7。
输入解题思路,AI测评打分。不知道怎么写?