#GL0000375. Mảng nguyên tố cùng nhau (Coprime Arrays)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mảng nguyên tố cùng nhau (Coprime Arrays)
Coprime Arrays
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An array is called coprime when . Equal elements are allowed and positions matter: two arrays are distinct if their values differ at any position.
Given positive integers , for every let be the number of coprime arrays of length with all elements in , reduced modulo .
Because can be as large as two million, do not output the individual . Output only
where means the bitwise XOR of the nonnegative integers and . XOR is not exponentiation; it is applied after reducing modulo .
Input
A single line containing two integers .
Output
Print a single integer: the XOR-based sum modulo .
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3 4
Output
82
Explanation
Here . Hence the required sum is .
Example 2
Input
2000000 8
Output
339310063
Explanation
The length is far too large for enumeration. Möbius inversion counts arrays by GCD and the answers are combined with XOR.