QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 512 MB 총점: 100 해킹 가능 ✓

#20240. Exponent

통계

The exponent of a group is the least common multiple of the orders of all elements in the group, but this has nothing to do with this problem. It's just to make the title start with E.

Little Ma gives you a positive integer $n$.

For each integer $a$ with $1 \le a \le n$, define $\operatorname{ord}_n(a)$ as the smallest positive integer $x$ satisfying:

$$ a^x \equiv 1 \pmod n $$

If no such positive integer $x$ exists, define $\operatorname{ord}_n(a)=0$.

Compute:

$$ \sum_{a=1}^{n}\operatorname{ord}_n(a) $$

Input

The first line contains an integer $T$ $(1\leq T\leq 10^3)$, the number of test cases.

Each of the next $T$ lines contains one positive integer $n$ $(1\leq n\leq 10^9)$.

Output

For each test case, output one integer in a single line: the required sum.

Examples

Input 1

5
1
5
8
54
9653618

Output 1

1
11
7
183
9856882167209

Input 2

5
48
2
4
8
16

Output 2

47
1
3
7
23

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.