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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var K = cin.ReadInt;
			var F = new ResidueField((int)Round(Pow(10, 9)) + 7);
			var has = new long[K + 1];
			for(int i = K; i >= 1; i--) {
				has[i] = F.Pow(K / i, N);
				for(int j = 2; j*i <= K; j++) {
					has[i] -= has[i * j];
				}
				has[i] = F.mod(has[i]);
			}
			var Res = 0L;
			for(int i = 1; i <= K; i++) {
				Res = F.Add(Res, i * has[i]);
			}
			Console.WriteLine(Res);
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x] = A[y];
			A[y] = tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
	}
	class ResidueField {
		public readonly long modulo;
		public ResidueField(int mModulo) {
			modulo = mModulo;
		}
		private long[] factorialTable = { 1 };
		private int factorialTableLastIndex { get { return factorialTable.Length - 1; } }
		public long mod(long x) => x < 0 ? x % modulo + modulo : x % modulo;
		public long Add(long a, long b) => mod(a + b);
		public long Sub(long a, long b) => mod(a - b);
		public long Mul(long a, long b) => mod(a * b);
		public long Pow(long a, long n) {
			if(n == 0) return 1;
			var R = 1L;
			n = n < 0 ? n % (modulo - 1) + (modulo - 1) : n % (modulo - 1);
			for(; n > 0; a = Mul(a, a), n >>= 1) {
				if((n & 1) != 0) R = Mul(R, a);
			}
			return R;
		}
		private static long extgcd(long a, long b, ref long x, ref long y) {
			if(b == 0) {
				x = 1; y = 0; return a;
			}
			var q = a / b;
			var g = extgcd(b, a - q * b, ref x, ref y);
			var z = x - q * y;
			x = y; y = z;
			return g;
		}
		public long Inv(long a) {
			if(a == 0) throw new DivideByZeroException();
			long x = 0, y = 0;
			extgcd(a, modulo, ref x, ref y);
			return mod(x);
		}
		public long Div(long a, long b) => Mul(a, Inv(b));
		public void ExpandFactorialTable(int N) {
			var k = factorialTableLastIndex;
			Array.Resize(ref factorialTable, N + 1);
			for(int i = k + 1; i <= N; i++) {
				if(i == 0) { factorialTable[i] = 1; continue; }
				factorialTable[i] = Mul(factorialTable[i - 1], i);
			}
		}
		public long Factorial(int n) {
			if(n > factorialTableLastIndex)
				ExpandFactorialTable(n);
			return factorialTable[n];
		}
		public long Permutation(int n, int k) {
			if(k < 0 || k > n) return 0;
			return Div(Factorial(n), Factorial(n - k));
		}
		public long Combination(int n, int k) {
			if(k < 0 || k > n) return 0;
			return Div(Factorial(n), Mul(Factorial(k), Factorial(n - k)));
		}

	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}