QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 256 MB Points totaux : 100

#8624. The First Problem

Statistiques

Given a permutation $P_1, P_2, \dots, P_n$ of $1$ to $n$, calculate the sum of $P_i \cdot P_j \cdot P_k$ for all triples $(i, j, k)$ such that $1 \le i, j, k \le n$ and $\gcd(i, j) = \gcd(j, k) = \gcd(k, i) = 1$.

The answer should be taken modulo $2^{30}$.

Input

The first line contains a positive integer $n$.

The next line contains $n$ positive integers $P_1, P_2, \dots, P_n$.

Output

Output the answer.

Constraints

  • $20\%$, $n \le 100$
  • $40\%$, $n \le 2000$
  • $100\%$, $n \le 10^5$
  • Among these, $10\%$ of the test cases have $n = 10^5$ and $P_i = i$.

Examples

Input 1

5
3 4 2 5 1

Output 1

981

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.