Sum of gcd of Tuples (Hard)

AtCoder
IDabc162_e
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3 2
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$.
Input #2
3 200
Output #2
10813692
Input #3
100000 100000
Output #3
742202979

Be sure to print the sum modulo $(10^9+7)$.
API Response (JSON)
{
  "problem": {
    "name": "Sum of gcd of Tuples (Hard)",
    "description": {
      "content": "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 t",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc162_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Consider sequences ${A_1,...,A_N}$ of length $N$ consisting of integers between $1$ and $K$ (inclusive).\nThere are $K^N$ such sequences. Find the sum of $\\gcd(A_1, ..., A_N)$ over all of them.\nSince t...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments