QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 512 MB Total points: 100 Difficulty: [show]

#1516. Power

Statistics

For a given prime $P$, we define $S(x)$ as the sequence of length $P$ given by $\{x^0\bmod P, x^1\bmod P, \dots, x^{P-1}\bmod P\}$, and we define $T(x)$ as the prefix maximum sequence of $S(x)$, i.e., $T(x)[p] = \max_{i=1}^p S(x)[i]$.

Given $T$ test cases, for each input $x$, you need to calculate the sum of the elements in $T(x)$, without taking any modulo.

For example, when $P=5$, $S(2)=\{1,2,4,3,1\}$, $T(2)=\{1,2,4,4,4\}$, so the sum of the elements in $T(2)$ is $15$.

Please note the data generation method.

Input

The first line contains two positive integers $P$ and $T$, representing the modulus and the number of test cases.

The next $T$ lines each contain a positive integer $x$, representing a test case.

Output

$T$ lines, each containing the answer for the corresponding test case.

Examples

Input 1

233 3
1
3
33

Output 1

233
51426
53224

Constraints

Each subtask contains no more than 15 test cases, $T=200$, $P$ is chosen independently and uniformly at random from primes within the specified range, and each $x$ is generated independently and uniformly at random in $[1, P)$.

Subtask 1 (10pts): $P\in [900, 1000]$.

Subtask 2 (20pts): $P\in [0.9\times 10^7, 10^7]$.

Subtask 3 (30pts): $P\in [0.9\times 10^8, 10^8]$.

Subtask 4 (40pts): $P\in [0.9\times 10^9, 10^9]$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.