A^n - 1

AtCoder
IDarc191_c
Time2000ms
Memory256MB
Difficulty
You are given a positive integer $N$ between $1$ and $10^9$, inclusive. Find one pair of positive integers $(A, M)$ satisfying the following conditions. It can be proved that such a pair of integers always exists under the constraints. * Both $A$ and $M$ are positive integers between $1$ and $10^{18}$, inclusive. * There exists a positive integer $n$ such that $A^n - 1$ is a multiple of $M$, and the smallest such $n$ is $N$. You are given $T$ test cases; solve each of them. ## Constraints * $1 \le T \le 10^4$ * $1 \le N \le 10^9$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $T$ $\text{case}_1$ $\text{case}_2$ $\vdots$ $\text{case}_T$ Here, $\text{case}_i$ denotes the $i$\-th test case. Each test case is given in the following format: $N$ [samples]
Samples
Input #1
4
3
16
1
55
Output #1
2 7
11 68
20250126 1
33 662

Consider $\text{case}_1$.
For example, if we choose $(A,M)=(2,7)$, then:

*   When $n=1$: $2^1 - 1 = 1$ is not a multiple of $7$.
*   When $n=2$: $2^2 - 1 = 3$ is not a multiple of $7$.
*   When $n=3$: $2^3 - 1 = 7$ is a multiple of $7$.

Hence, the smallest $n$ for which $A^n - 1$ is a multiple of $M$ is $3$. Therefore, $(A,M)=(2,7)$ is a correct solution. Other valid solutions include $(A,M)=(100,777)$.
API Response (JSON)
{
  "problem": {
    "name": "A^n - 1",
    "description": {
      "content": "You are given a positive integer $N$ between $1$ and $10^9$, inclusive. Find one pair of positive integers $(A, M)$ satisfying the following conditions. It can be proved that such a pair of integers a",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc191_c"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a positive integer $N$ between $1$ and $10^9$, inclusive.\nFind one pair of positive integers $(A, M)$ satisfying the following conditions. It can be proved that such a pair of integers a...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments