QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 10 Hackable ✓

#144. Primitive root / 原根

الإحصائيات

In modular arithmetic, a number $g$ is a primitive root modulo $n$ if every number a coprime to $n$ is congruent to a power of $g$ modulo $n$. That is, $g$ is a primitive root modulo $n$ if for every integer $a$ coprime to $n$, there is some integer $k$ for which $g^k \equiv a \pmod n$.

Given an integer $n$, you need to find any primitive root modulo $n$, or claim that it doesn't exist.

Input

The first line of the input consists a single integer $n$ ($1 \le n \le 10^{16}$).

Output

If there's no primitive root modulo $n$, print -1.

Otherwise, print a single integer $g$, indicating your solution. If there are multiple possible solutions, you may print any of them.

Example

Input 1

2

Output 1

1

Input 2

17

Output 2

3

Input 3

20014

Output 3

5

Input 4

230000

Output 4

-1

Scoring

Let $p \ge 3$ be an odd prime number, and $k > 0$ be a positive integer.

Test Set $m$ Constraints
$1$ $\le 1\,000$ $m = p$
$2$ $m = p^k$
$3$ None
$4$ $\le 10^6$ $m = p$
$5$ $m = p^k$
$6$ None
$7$ $\le 10^9$ $m = p$
$8$ $m = p^k$
$9$ None
$10$ $\le 10^{16}$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.