#P4449. 于神之怒加强版

    ID: 3375 远端评测题 2000ms 262MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学素数判断,质数,筛法前缀和

于神之怒加强版

Description

Given n,m,kn, m, k, compute

i=1nj=1mgcd(i,j)k\sum_{i=1}^n \sum_{j=1}^m \gcd(i,j)^k

and output the result modulo 109+710^9 + 7.

Input Format

There are multiple test cases in a single test file.

The first line contains two integers, the number of test cases TT and the given kk.

The next TT lines each contain two integers, nn and mm, for one test case.

Output Format

For each test case, output one line with a single integer representing the answer.

1 2
3 3
20

Hint

Constraints

For all test points, it is guaranteed that 1T2×1031 \leq T \leq 2 \times 10^3, 1n,m,k5×1061 \leq n, m, k \leq 5 \times 10^6.

Translated by ChatGPT 5