C - A^n - 1 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600600

問題文

11 以上 10910^9 以下の正整数 NN が与えられます。

以下の条件を共に満たす正整数の組 (A,M)(A,M) を一つ求めてください。ただし、制約下でそのような正整数の組が必ず存在することが証明できます。

  • A,MA,M はどちらも 11 以上 101810^{18} 以下の正整数である。
  • An1A^n-1MM の倍数となるような正整数 nn が存在し、その最小値は NN である。

TT 個のテストケースが与えられるので、それぞれについて答えを求めてください。

制約

  • 1T1041\le T\le 10^4
  • 1N1091\le N\le 10^9
  • 入力される値は全て整数

入力

入力は以下の形式で標準入力から与えられる。

TT
case1\text{case}_1
case2\text{case}_2
\vdots
caseT\text{case}_T

ここで、 casei\text{case}_iii 番目のテストケースを意味する。

各テストケースは以下の形式で与えられる。

NN

出力

それぞれのケースについて、条件を満たす正整数の組 (A,M)(A,M) を以下の形式で出力せよ。

AA MM

条件を満たす解が複数存在する場合、どれを出力しても正解とみなされる。


入力例 1Copy

Copy
4
3
16
1
55

出力例 1Copy

Copy
2 7
11 68
20250126 1
33 662

case1\text{case}_1 について考えます。

例えば (A,M)=(2,7)(A,M)=(2,7) とすると

  • n=1n=1 のとき: 211=12^1-1=177 の倍数ではない。
  • n=2n=2 のとき: 221=32^2-1=377 の倍数ではない。
  • n=3n=3 のとき: 231=72^3-1=777 の倍数である。

となり、条件を満たす最小の nn33 になることが確認できます。したがって、 (A,M)=(2,7)(A,M)=(2,7) を出力すると正答となります。 この他にも、例えば (A,M)=(100,777)(A,M)=(100,777) などが条件を満たします。

Score : 600600 points

Problem Statement

You are given a positive integer NN between 11 and 10910^9, inclusive.

Find one pair of positive integers (A,M)(A, M) satisfying the following conditions. It can be proved that such a pair of integers always exists under the constraints.

  • Both AA and MM are positive integers between 11 and 101810^{18}, inclusive.
  • There exists a positive integer nn such that An1A^n - 1 is a multiple of MM, and the smallest such nn is NN.

You are given TT test cases; solve each of them.

Constraints

  • 1T1041 \le T \le 10^4
  • 1N1091 \le N \le 10^9
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
\vdots
caseT\text{case}_T

Here, casei\text{case}_i denotes the ii-th test case.
Each test case is given in the following format:

NN

Output

For each test case, print a pair of positive integers (A,M)(A, M) in the following format:

AA MM

If there are multiple valid solutions, any one of them is considered correct.


Sample Input 1Copy

Copy
4
3
16
1
55

Sample Output 1Copy

Copy
2 7
11 68
20250126 1
33 662

Consider case1\text{case}_1.

For example, if we choose (A,M)=(2,7)(A,M)=(2,7), then:

  • When n=1n=1: 211=12^1 - 1 = 1 is not a multiple of 77.
  • When n=2n=2: 221=32^2 - 1 = 3 is not a multiple of 77.
  • When n=3n=3: 231=72^3 - 1 = 7 is a multiple of 77.

Hence, the smallest nn for which An1A^n - 1 is a multiple of MM is 33. Therefore, (A,M)=(2,7)(A,M)=(2,7) is a correct solution. Other valid solutions include (A,M)=(100,777)(A,M)=(100,777).



2025-04-24 (Thu)
12:47:48 +00:00