#P10031. 「Cfz Round 3」Xor with Gcd

    ID: 11155 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学洛谷原创O2优化最大公约数 gcd洛谷月赛Ad-hoc

「Cfz Round 3」Xor with Gcd

Background

She is a grain of sand that sneaks in at midnight, drifting with the sea breeze.

The aurora makes a wish for tomorrow together with her.

She leaps up, and radio waves spread across the sky, yet the sea remains calm.

“May the world be full of blooming flowers.”

Problem Description

Given an integer nn.

You need to compute i=1ngcd(i,n)\bigoplus\limits_{i=1}^{n} \gcd(i,n), that is, the value of $\gcd(1,n) \oplus \gcd(2,n) \oplus \cdots \oplus \gcd(n,n)$. Here, gcd(a,b)\gcd(a,b) denotes the greatest common divisor, and \bigoplus denotes bitwise XOR, i.e. ^ in C++.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, which represents the number of test cases.

Then each test case follows. For each test case, one line contains one integer nn.

Output Format

For each test case, output one line with one integer, representing the value of i=1ngcd(i,n)\bigoplus\limits_{i=1}^{n} \gcd(i,n).

3
2
3
6

3
3
5

Hint

"Sample Explanation #1"

For the 11st test case, $\bigoplus\limits_{i=1}^{2} \gcd(i,2)=\gcd(1,2)\oplus\gcd(2,2)=1\oplus2=3$.

For the 22nd test case, $\bigoplus\limits_{i=1}^{3} \gcd(i,3)=\gcd(1,3)\oplus\gcd(2,3)\oplus\gcd(3,3)=1\oplus1\oplus3=3$.

"Constraints"

For all testdata, 1T1001 \le T \le 100, 1n10181 \le n \le 10^{18}.

You can only get the score for this problem if you pass all test points.

Translated by ChatGPT 5