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# (Mono-mcs 6.8.0.105) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    static class Solve
    {
        public static void Answer()
        {
            var NK = IO_ShortCut.ReadSplitInt;
            var N = NK[0];
            var K = NK[1];

            var cnt = new int[K + 1];
            for (int i = K; i >= 1; i--)
            {
                var tmp = Modulo.Pow(K / i, N);
                int rate = 2;
                while (i * rate <= K)
                {
                    tmp = Modulo.Sub(tmp, cnt[i * rate]);
                    rate++;
                }
                cnt[i] = tmp;
            }

            int ans = 0;
            for (int i = K; 1 <= i; i--)
            {
                var sum = Modulo.Mul(cnt[i], i);
                ans = Modulo.Add(ans, sum);
            }

            WriteLine(ans);
        }

        public static int GCD(int a, int b)
        {
            int gcd;
            while (true)
            {
                if (a == b)
                {
                    gcd = a;
                    break;
                }

                if (b > a)
                {
                    int tmp = b;
                    b = a;
                    a = tmp;
                }
                a -= b;
            }
            return gcd;
        }
    }

    public class Modulo
    {
        private readonly static int M = 1000000007;

        /// <summary>(a * b) % M</summary>
        public static int Mul(int a, int b)
        {
            return (int)(Math.BigMul(a, b) % M);
        }
        /// <summary>(a + b) % M</summary>
        public static int Add(int a, int b)
        {
            long v = a + b;
            if (M <= v)
                v = v - M;
            return (int)v;
        }
        /// <summary>(a - b) % M</summary>
        public static int Sub(int a, int b)
        {
            int v = a - b;
            if (v < 0) v = M + v;
            return v;
        }

        /// <summary>(aのm乗) % M</summary>
        /// <see cref="https://www.youtube.com/watch?v=gdQxKESnXKs のD問題"/>
        public static int Pow(int a, int m)
        {
            switch (m)
            {
                case 0:
                    return 1;
                case 1:
                    return a % M;
                default:
                    int p1 = Pow(a, m / 2);
                    int p2 = Mul(p1, p1);
                    return ((m % 2) == 0) ? p2 : Mul(p2, a);
            }
        }

        /// <summary>
        /// (a / b) % M
        /// ※フェルマーの小定理による
        /// </summary>
        /// <see cref="https://www.youtube.com/watch?v=gdQxKESnXKs のD問題"/>
        public static int Div(int a, int b)
        {
            return Mul(a, Pow(b, M - 2));
        }

        /// <summary>
        /// コンストラクタ ※n! % M および nCr % M を使用する場合には必要
        /// </summary>
        private readonly int[] m_facs;
        public Modulo(int n)
        {
            // x が n までの、x! % M の結果を配列に保持する
            m_facs = new int[n + 1];
            m_facs[0] = 1;
            for (int i = 1; i <= n; ++i)
            {
                m_facs[i] = Mul(m_facs[i - 1], i);
            }
        }

        /// <summary>n! % M</summary>
        public int Fac(int n)
        {
            return m_facs[n];
        }
        /// <summary>
        /// 組み合わせ nCr % M
        /// </summary>
        /// <see cref="https://www.youtube.com/watch?v=gdQxKESnXKs のD問題"/>
        public int Ncr(int n, int r)
        {
            if (n < r) { return 0; }
            if (n == r) { return 1; }
            int res = Fac(n);
            res = Div(res, Fac(r));
            res = Div(res, Fac(n - r));
            return res;
        }

        /// <summary>
        /// 組み合わせ nCr % M を高速に計算する
        /// ※n!のテーブルを使用しない版（Nが大きくても計算できる）
        /// </summary>
        public static int CalcNcr(int n, int r)
        {
            if (n - r < r) return CalcNcr(n, n - r);

            long ansMul = 1;
            long ansDiv = 1;
            for (int i = 0; i < r; i++)
            {
                ansMul *= n - i;
                ansDiv *= i + 1;
                ansMul %= M;
                ansDiv %= M;
            }

            return Div((int)ansMul, (int)ansDiv);
        }
    }

    static class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        #endregion
    }
}