QOJ.ac

QOJ

حد الوقت: 25 s حد الذاكرة: 2048 MB مجموع النقاط: 100

#8327. Summation of Multiplicative Functions $10^{13}$ FFT-friendly Version

الإحصائيات

A long time ago, you discovered a magical function $f(x)$ that satisfies many magical properties:

  1. $f(1)=1$.
  2. $f(p^e)= ae + bp$ (where $p$ is a prime number).
  3. $f(xy)=f(x)f(y)$ (where $x$ and $y$ are coprime).

Let $S(m)=\sum\limits_{i=1}^m f(i) \bmod 469762049$. You need to calculate $S(\lfloor n/i\rfloor)$ for $i=1,2,3,\cdots,n$, then output the XOR sum of the unique values.

Note: To encourage the exploration of new methods, this problem uses the carefully chosen number $469762049$. The field $\mathbb{Z} / 469762049 \mathbb{Z}$ has a $2^{26}$-th primitive root of unity, and $3$ is a primitive root of this field.

Input

The first line contains a positive integer $T$, representing the number of test cases.

Each of the next $T$ lines contains three positive integers $n_i$, $a_i$, and $b_i$, where $a_i$ and $b_i$ are the parameters $a$ and $b$ from property 2 of $f(x)$.

Output

Output $T$ lines, where the $i$-th line contains a non-negative integer representing the XOR sum of the unique values in the set $\left\{S(\lfloor n/i\rfloor)\right\}_{i\in[1,n_i]}$.

Examples

Input 1

1
6 2 2

Output 1

90

Note 1

The set of unique values is $\{1, 7, 15, 83\}$, and their XOR sum is $90$.

Input 2

1
233333 29 31

Output 2

227062462

Input 3

1
9876543210 98765 43210

Output 3

78615365

Subtasks

$1 \leq T \leq 10^4$.

$0 \leq a_i, b_i < 469762049$.

When $T = 1$, $1 \leq n \leq 10^{13}$; otherwise, $1 \leq T \sqrt{\max_{i=1}^T n_i} \leq 10^6$.

Note

Efficient methods to solve this problem are relatively uncommon. Some resources (https://github.com/yosupo06/library-checker-problems/issues/1118) have been collected for reference.

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.