CF1549A.Gregor and Cryptography

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.

Gregor's favorite prime number is PP. Gregor wants to find two bases of PP. Formally, Gregor is looking for two integers aa and bb which satisfy both of the following properties.

  • P mod a=P mod bP \bmod a = P \bmod b, where x mod yx \bmod y denotes the remainder when xx is divided by yy, and
  • 2≤a<b≤P2 \le a \lt b \le P.

Help Gregor find two bases of his favorite prime number!

格雷戈尔正在学习 RSA 密码学,尽管他并不理解 RSA 的工作原理,但他现在对素数及其因式分解着了迷。

格雷戈尔最喜爱的素数是 PP。他想为 PP 找到两个“底数”。形式化地说,格雷戈尔在寻找两个整数 aa 和 bb,它们同时满足以下两个条件:

  • P mod a=P mod bP \bmod a = P \bmod b,其中 x mod yx \bmod y 表示 xx 除以 yy 所得的余数;
  • 2≤a<b≤P2 \le a \lt b \le P。

请帮助格雷戈尔找到他最喜爱的素数的两个底数!

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000).

Each subsequent line contains the integer PP (5≤P≤1095 \le P \le {10}^9), with PP guaranteed to be prime.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。

随后的每一行包含一个整数 PP(5≤P≤1095 \le P \le {10}^9),且保证 PP 为质数。

输出格式

Your output should consist of tt lines. Each line should consist of two integers aa and bb (2≤a<b≤P2 \le a \lt b \le P). If there are multiple possible solutions, print any.

你的输出应包含 tt 行。每行应包含两个整数 aa 和 bb(满足 2≤a<b≤P2 \le a \lt b \le P)。若存在多个可行解,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    17
    5

    输出#1

    3 5
    2 4

说明/提示

The first query is P=17P=17. a=3a=3 and b=5b=5 are valid bases in this case, because 17 mod 3=17 mod 5=217 \bmod 3 = 17 \bmod 5 = 2. There are other pairs which work as well.

In the second query, with P=5P=5, the only solution is a=2a=2 and b=4b=4.

第一个查询中,P=17P=17。此时 a=3a=3 和 b=5b=5 是有效的底数,因为 17 mod 3=17 mod 5=217 \bmod 3 = 17 \bmod 5 = 2。还存在其他满足条件的数对。

第二个查询中,当 P=5P=5 时,唯一解为 a=2a=2 和 b=4b=4。

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

首页