Problem:
Score : 500 points

Problem Statement

Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive).

There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them.

Since this sum can be enormous, print the value modulo (10^9+7).

Here \gcd(A_1, ..., A_N) denotes the greatest common divisor of A_1, ..., A_N.

Constraints

2 \leq N \leq 10^5

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K

Output

Print the sum of \gcd(A_1, ..., A_N) over all K^N sequences, modulo (10^9+7).

Sample Input 1

3 2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

3 200

Sample Output 2

10813692

Sample Input 3

100000 100000

Sample Output 3

742202979

Be sure to print the sum modulo (10^9+7).

Solution in Kotlin (1.3.71) (judge verdict: Accepted)

import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val k = scn.nextInt()

	val arr = Array(k+1){ ModInt.ZERO}
	var ans = ModInt(0)
	for (i in k downTo 1){
		val t = k/i
		var cnt = ModInt.pow(t, n)
		for (p in 2..t){
			cnt -= arr[p*i]
		}
		arr[i] = cnt
		ans += cnt*i
	}
	println(ans)
}

class ModInt {
	var v: Long
		private set
	constructor(v: Int){
		this.v = when {
			v>=0 -> v.toLong() % MOD
			v==Int.MIN_VALUE -> 852516373
			else -> MOD.toLong() - (-v%MOD)
		}
	}
	constructor(v: Long){
		this.v = when {
			v>=0 -> v % MOD
			v==Long.MIN_VALUE -> 708828003
			else -> MOD - (-v%MOD)
		}
	}

	override fun toString() = v.toString()
	fun toInt() = v.toInt()
	fun toLong() = v
	override fun equals(other: Any?): Boolean {
		return if (other is ModInt) v == other.v else false
	}
	override fun hashCode() = 31*17 + v.hashCode()

	operator fun unaryPlus() = this
	operator fun unaryMinus() = ModInt(MOD-this.v)

	private operator fun plus(o: Long) = ModInt(this.v + o)
	operator fun plus(o: ModInt) = this.plus(o.v)
	operator fun plus(o: Int) = this.plus(o.toLong())
	private operator fun minus(o: Long) = this.plus(-o)
	operator fun minus(o: ModInt) = this.minus(o.v)
	operator fun minus(o: Int) = this.minus(o.toLong())
	private operator fun times(o: Long) = ModInt(this.v*o)
	operator fun times(o: ModInt) = this.times(o.v)
	operator fun times(o: Int) = this.times(o.toLong())
	private operator fun div(o: Long) = this.times(pow(o, MOD-2))
	operator fun div(o: ModInt) = this.div(o.v)
	operator fun div(o: Int) = this.div(o.toLong())

	operator fun inc() = this.plus(1)
	operator fun dec() = this.minus(1)

	companion object{
		const val MOD = 1000000007
		val ZERO = ModInt(0)

		private fun pow(b:Long, e: Int): ModInt{
			if (b==1L) return ModInt(1)
			var ans = 1L
			var b = b; var e = e
			while (e!=0){
				if (e%2==1) ans = (ans*b)%MOD
				b = (b*b)%MOD
				e /= 2
			}
			return ModInt(ans)
		}
		fun pow(b: Int, e: Int): ModInt = pow(b.toLong(), e)
		fun pow(b: ModInt, e: Int): ModInt = pow(b.v, e)
	}
}