PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000375. Mảng nguyên tố cùng nhau (Coprime Arrays)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mảng nguyên tố cùng nhau (Coprime Arrays)

Coprime Arrays

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

An array a=(a1,a2,…,an)a=(a_1,a_2,\ldots,a_n) is called coprime when gcd⁡(a1,a2,…,an)=1\gcd(a_1,a_2,\ldots,a_n)=1. Equal elements are allowed and positions matter: two arrays are distinct if their values differ at any position.

Given positive integers n,kn,k, for every 1≤i≤k1\le i\le k let bib_i be the number of coprime arrays of length nn with all elements in [1,i][1,i], reduced modulo P=109+7P=10^9+7.

Because kk can be as large as two million, do not output the individual bib_i. Output only

(∑i=1k(bi⊕i)) mod P,\left(\sum_{i=1}^{k}(b_i\oplus i)\right)\bmod P,

where ⊕\oplus means the bitwise XOR of the nonnegative integers bib_i and ii. XOR is not exponentiation; it is applied after reducing bib_i modulo PP.

Input

A single line containing two integers n,kn,k.

Output

Print a single integer: the XOR-based sum modulo 109+710^9+7.

Subtasks

  • Subtask 1 (20 points): 1≤n≤51\le n\le5, 1≤k≤81\le k\le8.

  • Subtask 2 (30 points): 1≤n≤20 0001\le n\le20\,000, 1≤k≤200 0001\le k\le200\,000.

  • Subtask 3 (50 points): 1≤n,k≤2⋅1061\le n,k\le2\cdot10^6.

Examples

Example 1

Input

3 4

Output

82

Explanation

Here b1=1,b2=7,b3=25,b4=55b_1=1,b_2=7,b_3=25,b_4=55. Hence the required sum is 0+5+26+51=820+5+26+51=82.

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.