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 (GCC 9.2.1) (judge verdict: Runtime Error)

#include <stdio.h>
#include <stdbool.h>
#define N 16
int kouyakusuu(int a,int b);
int  buffer[N];
bool used[N + 1];

void print_perm(int n)
{
//  for (int i = 0; i < n; i++)
//    printf("%d ", buffer[i]);
//  printf("\n");
}

void perm_sub(int n, int m)
{
  if (n == m)
    print_perm(n);
  else {
    for (int i = 1; i <= n; i++) {
      if (used[i]) continue;
      buffer[m] = i;
      used[i] = true;
      perm_sub(n, m + 1);
      used[i] = false;
    }
  }
}

void permutations(int n)
{
  if (n > 0 || n < N) perm_sub(n, 0);
}

int main(){
    int ans,k,n;
    long int tmp;
    scanf("%d %d",&n,&k);
      permutations(n);
      permutations(k);
    for(int i=1;i<n;i++){
        tmp+=kouyakusuu(buffer[0],buffer[i]);
    }
    ans=tmp%(10^9+7);
    printf("%d\n",ans);
}
int kouyakusuu(int a,int b){
    int tmp,r;
    /* 自然数 a > b を確認・入替 */
     if(a<b){
       tmp = a;
       a = b;
       b = tmp;
     }
     /* ユークリッドの互除法 */
     r = a % b;
     while(r!=0){
       a = b;
       b = r;
       r = a % b;
     }
     /* 最大公約数を出力 */
    return b;
}
//int sequence(int x,int y){//二つの公約数を返す
//    int n=kouyakusuu(x,y);
//    n=kouyakusuu()
//    return n;
//}