A14430 | Gregor and Cryptography
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $P$ . Gregor wants to find two bases of $P$ . Formally, Gregor is looking for two integers $a$ and $b$ which satisfy both of the following properties.
- $P \bmod a = P \bmod b$ , where $x \bmod y$ denotes the remainder when $x$ is divided by $y$ , and
- $2 \le a < b \le P$ .
Help Gregor find two bases of his favorite prime number!
Gregor's favorite prime number is $P$ . Gregor wants to find two bases of $P$ . Formally, Gregor is looking for two integers $a$ and $b$ which satisfy both of the following properties.
- $P \bmod a = P \bmod b$ , where $x \bmod y$ denotes the remainder when $x$ is divided by $y$ , and
- $2 \le a < b \le P$ .
Help Gregor find two bases of his favorite prime number!
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 1000$ ).
Each subsequent line contains the integer $P$ ( $5 \le P \le {10}^9$ ), with $P$ guaranteed to be prime.
Each subsequent line contains the integer $P$ ( $5 \le P \le {10}^9$ ), with $P$ guaranteed to be prime.
输出格式
Your output should consist of $t$ lines. Each line should consist of two integers $a$ and $b$ ( $2 \le a < b \le P$ ). If there are multiple possible solutions, print any.
输入输出样例
输入 #1
2 17 5
输出 #1
3 5 2 4
The first query is $P=17$ . $a=3$ and $b=5$ are valid bases in this case, because $17 \bmod 3 = 17 \bmod 5 = 2$ . There are other pairs which work as well.
In the second query, with $P=5$ , the only solution is $a=2$ and $b=4$ .
In the second query, with $P=5$ , the only solution is $a=2$ and $b=4$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted