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-10241024, a 10241024-bit long product of two prime numbers. To this date, nobody was able to claim the prize. We want you to factorise a 10241024-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 xx and yy are integers between 00 and n−1n-1. Returns (x+y) mod n(x+y) \bmod n.
  • - x y where xx and yy are integers between 00 and n−1n-1. Returns (x−y) mod n(x-y) \bmod n.
  • * x y where xx and yy are integers between 00 and n−1n-1. Returns (x⋅y) mod n(x \cdot y) \bmod n.
  • / x y where xx and yy are integers between 00 and n−1n-1 and yy is coprime with nn. Returns (x⋅y−1) mod n(x \cdot y^{-1}) \bmod n where y−1y^{-1} is multiplicative inverse of yy modulo nn. If yy is not coprime with nn, then −1-1 is returned instead.
  • sqrt x where xx is integer between 00 and n−1n-1 coprime with nn. Returns yy such that y2 mod n=xy^2 \bmod n = x. If there are multiple such integers, only one of them is returned. If there are none, −1-1 is returned instead.
  • ^ x y where xx and yy are integers between 00 and n−1n-1. Returns xy mod n{x^y \bmod n}.

Find the factorisation of nn that is a product of between 22 and 1010 distinct prime numbers, all of form 4x+34x + 3 for some integer xx.

Because of technical issues, we restrict number of requests to 100100.

整数分解是困难的。RSA 分解挑战赛曾为分解 RSA-1024(一个由两个素数相乘得到的 1024 位整数)提供 100 000 美元奖金。截至目前,尚无人成功领取该奖金。本题要求你对一个 1024 位整数进行质因数分解。

由于你所选用的编程语言可能不支持大整数运算,我们将为你提供一个非常简单的计算器。

要使用该计算器,你可在标准输出上打印查询语句,并从标准输入读取结果。支持的运算如下:

  • + x y:其中 xx 和 yy 是介于 00 与 n−1n-1 之间的整数。返回 (x+y) mod n(x+y) \bmod n。
  • - x y:其中 xx 和 yy 是介于 00 与 n−1n-1 之间的整数。返回 (x−y) mod n(x-y) \bmod n。
  • * x y:其中 xx 和 yy 是介于 00 与 n−1n-1 之间的整数。返回 (x⋅y) mod n(x \cdot y) \bmod n。
  • / x y:其中 xx 和 yy 是介于 00 与 n−1n-1 之间的整数,且 yy 与 nn 互质。返回 (x⋅y−1) mod n(x \cdot y^{-1}) \bmod n,其中 y−1y^{-1} 是 yy 模 nn 的乘法逆元。若 yy 与 nn 不互质,则返回 −1-1。
  • sqrt x:其中 xx 是介于 00 与 n−1n-1 之间且与 nn 互质的整数。返回满足 y2 mod n=xy^2 \bmod n = x 的整数 yy。若存在多个这样的整数,则仅返回其中一个;若不存在,则返回 −1-1。
  • ^ x y:其中 xx 和 yy 是介于 00 与 n−1n-1 之间的整数。返回 xy mod n{x^y \bmod n}。

请对整数 nn 进行质因数分解,其中 nn 是 22 至 1010 个互异素数的乘积,且每个素数均形如 4x+34x + 3(xx 为某整数)。

由于技术限制,你最多只能发出 100100 次请求。

输入格式

The only line contains a single integer nn (21≤n≤2102421 \leq n \leq 2^{1024}). It is guaranteed that nn is a product of between 22 and 1010 distinct prime numbers, all of form 4x+34x + 3 for some integer xx.

唯一一行包含一个整数 nn(21≤n≤2102421 \leq n \leq 2^{1024})。保证 nn 是 22 到 1010 个互异素数的乘积,且每个素数均具有 4x+34x + 3 的形式(其中 xx 为某个整数)。

输出格式

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 kk is the number of prime factors of nn, and pip_i 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 kk (2≤k≤102 \leq k \leq 10) — the number of prime factors of nn.

The second should contain kk space separated integers p1,p2,…,pkp_1, p_2, \dots, p_k (21≤n≤2102421 \leq n \leq 2^{1024}) — the prime factors of nn. All prime factors have to be of form 4x+34x + 3 for some integer xx. They all have to be distinct.

你可以输出任意数量的查询,只要满足时间限制(详见“交互”部分)。

当你认为自己已经得出答案时,请输出一行形如 ! k p_1 p_2 ... p_k 的答案,其中 kk 是 nn 的不同质因数的个数,pip_i 是 nn 的所有不同质因数。质因数的输出顺序可以任意。

Hack 输入格式

对于 Hack,需使用如下格式:

第一行应包含 kk(2≤k≤102 \leq k \leq 10)——即 nn 的质因数个数。

第二行应包含 kk 个以空格分隔的整数 p1,p2,…,pkp_1, p_2, \dots, p_k(满足 21≤n≤2102421 \leq n \leq 2^{1024})——即 nn 的质因数。所有质因数均须形如 4x+34x + 3(其中 xx 为某整数),且互不相同。

输入输出样例

  • 输入#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=21n = 21. Then, we ask for:

  1. (12+16) mod 21=28 mod 21=7(12 + 16) \bmod 21 = 28 \bmod 21 = 7.
  2. (6−10) mod 21=−4 mod 21=17(6 - 10) \bmod 21 = -4 \bmod 21 = 17.
  3. (8⋅15) mod 21=120 mod 21=15(8 \cdot 15) \bmod 21 = 120 \bmod 21 = 15.
  4. (5⋅4−1) mod 21=(5⋅16) mod 21=80 mod 21=17(5 \cdot 4^{-1}) \bmod 21 = (5 \cdot 16) \bmod 21 = 80 \bmod 21 = 17.
  5. Square root of 1616. The answer is 1111, as (11⋅11) mod 21=121 mod 21=16(11 \cdot 11) \bmod 21 = 121 \bmod 21 = 16. Note that the answer may as well be 1010.
  6. Square root of 55. There is no xx such that x2 mod 21=5x^2 \bmod 21 = 5, so the output is −1-1.
  7. (612) mod 21=2176782336 mod 21=15(6^{12}) \bmod 21 = 2176782336 \bmod 21 = 15.

We conclude that our calculator is working, stop fooling around and realise that 21=3⋅721 = 3 \cdot 7.

我们首先读取第一行,其中包含整数 n=21n = 21。然后,我们依次计算:

  1. (12+16) mod 21=28 mod 21=7(12 + 16) \bmod 21 = 28 \bmod 21 = 7。
  2. (6−10) mod 21=−4 mod 21=17(6 - 10) \bmod 21 = -4 \bmod 21 = 17。
  3. (8⋅15) mod 21=120 mod 21=15(8 \cdot 15) \bmod 21 = 120 \bmod 21 = 15。
  4. (5⋅4−1) mod 21=(5⋅16) mod 21=80 mod 21=17(5 \cdot 4^{-1}) \bmod 21 = (5 \cdot 16) \bmod 21 = 80 \bmod 21 = 17。
  5. 1616 的平方根。答案为 1111,因为 (11⋅11) mod 21=121 mod 21=16(11 \cdot 11) \bmod 21 = 121 \bmod 21 = 16。注意:答案也可能是 1010。
  6. 55 的平方根。不存在满足 x2 mod 21=5x^2 \bmod 21 = 5 的 xx,因此输出 −1-1。
  7. (612) mod 21=2176782336 mod 21=15(6^{12}) \bmod 21 = 2176782336 \bmod 21 = 15。

我们由此确认计算器工作正常,停止胡闹,并意识到 21=3⋅721 = 3 \cdot 7。

输入解题思路,AI测评打分。不知道怎么写?

首页