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: Wrong Answer)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

#define BUF_SIZE 30

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define DIVISOR 1000000007
#define NUM_MAX 100000
// 2*3*7*11*13*15
#define DIVS_MAX 300
#define CNT_BIT_MAX 20
struct pair {
    int x;
    int y;
};

int asc(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}


void calc_power(uint64_t *powers, int size, int cnt) {
    int num,bit;
    uint64_t tmp[CNT_BIT_MAX] = {0};
    for(num = 0; num < size; num++) {
        uint64_t res = 1;
        tmp[0] = num;
        for(bit = 1; bit < CNT_BIT_MAX; bit++) {
            tmp[bit] = (tmp[bit-1]*tmp[bit-1])%DIVISOR;
        }
        for(bit = 0; bit < CNT_BIT_MAX; bit++) {
            if(!(cnt & (1<<bit))) continue;
            res = (res * tmp[bit])%DIVISOR;
        }
        powers[num] = res;
    }
    return;
}

int main(void) {
    int cnt, k;
    get_int2(&cnt, &k);
    int i;
    int cands[NUM_MAX+1] = {0};
    for(i = 1; i <= k; i++) {
        cands[i] = k/i;
    }
    uint64_t powers[NUM_MAX+1]; // (i)**(cnt)
    calc_power(powers, k+1, cnt);
    uint64_t ans = 0;
    int mod;
    for(mod = 1; mod <= k; mod++) {
        int mod2 = sqrt(0.5 + mod);
        int div;
        int sum = 0;
        // calc coef = (mod) - ((sum of mod's divs) - (mod))
        for(div = 1; div <= mod2; div++) {
            if(mod%div) break;
            sum += (div);
            if(div*div != mod) sum += (mod/div);
        }
        uint64_t coef = (mod*2 + DIVISOR - sum)%DIVISOR;
        ans = (ans + coef * powers[cands[mod]])%DIVISOR;
#ifdef DEBUG
        printf("[mod: %d] sum: %d => coef: %d ", mod, sum, mod*2-sum);
        printf(";; cands: %d, power: %llu\n", cands[mod], powers[cands[mod]]);
#endif
    }
    printf("%d\n", (int)ans);
    return 0;
}