∑ a i = 1 n ∑ a 2 = 1 n ⋯ ∑ a x = 1 n ( ∏ j = 1 x a j k ) f ( g c d ( a 1 , a 2 , … , a x ) ) × g c d ( a 1 , a 2 , … , a x ) \sum_{a_i = 1} ^{n} \sum_{a_2 = 1} ^{n} \dots \sum_{a_x = 1} ^{n} \left(\prod_{j = 1} ^{x} a_j ^ k \right)f(gcd(a_1, a_2, \dots, a_x))\times gcd(a_1, a_2, \dots, a_x) ai=1∑na2=1∑n⋯ax=1∑n(j=1∏xajk)f(gcd(a1,a2,…,ax))×gcd(a1,a2,…,ax)
= ∑ d = 1 n d f ( d ) ∑ a i = 1 n ∑ a 2 = 1 n ⋯ ∑ a x = 1 n ( ∏ j = 1 x a j k ) ( g c d ( a 1 , a 2 , … , a x ) = = d ) = \sum_{d = 1} ^{n}df(d)\sum_{a_i = 1} ^{n} \sum_{a_2 = 1} ^{n} \dots \sum_{a_x = 1} ^{n} \left(\prod_{j = 1} ^{x} a_j ^ k \right)(gcd(a_1, a_2, \dots, a_x) == d) =d=1∑ndf(d)ai=1∑na2=1∑n⋯ax=1∑n(j=1∏xajk)(gcd(a1,a2,…,ax)==d)
有 ∑ a i = 1 n ∑ a 2 = 1 n ⋯ ∑ a x = 1 n ( ∏ j = 1 x a j k ) = ( ∑ i = 1 n i k ) x 有\sum_{a_i = 1} ^{n} \sum_{a_2 = 1} ^{n} \dots \sum_{a_x = 1} ^{n} \left(\prod_{j = 1} ^{x} a_j ^ k \right) = \left(\sum_{i = 1} ^{n} i ^ k \right) ^ x 有ai=1∑na2=1∑n⋯ax=1∑n(j=1∏xajk)=(i=1∑nik)x
= ∑ d = 1 n d k d + 1 f ( d ) ( ∑ i = 1 n d i k ) x ( g c d ( a 1 , a 2 , … , a x ) = = 1 ) = \sum_{d = 1} ^{n}d ^ {kd + 1} f(d)\left(\sum_{i = 1} ^{\frac{n}{d}} i ^ k \right) ^ x (gcd(a_1, a_2, \dots, a_x) == 1) =d=1∑ndkd+1f(d)⎝⎛i=1∑dnik⎠⎞x(gcd(a1,a2,…,ax)==1)
= ∑ d = 1 n d k d + 1 f ( d ) ( ∑ i = 1 n d i k ) x ∑ t ∣ n d μ ( t ) = \sum_{d = 1} ^{n}d ^ {kd + 1} f(d)\left(\sum_{i = 1} ^{\frac{n}{d}} i ^ k \right) ^ x \sum_{t \mid \frac{n}{d}}\mu(t) =d=1∑ndkd+1f(d)⎝⎛i=1∑dnik⎠⎞xt∣dn∑μ(t)
= ∑ d = 1 n f ( d ) d d x + 1 ∑ t = 1 n d μ ( t ) t k x ( ∑ i = 1 n d t i k ) x = \sum_{d = 1} ^{n} f(d) d ^{dx + 1} \sum_{t = 1} ^{\frac{n}{d}} \mu(t) t^{kx} \left( \sum_{i = 1} ^{\frac{n}{dt}} i ^ k\right) ^ x =d=1∑nf(d)ddx+1t=1∑dnμ(t)tkx⎝⎛i=1∑dtnik⎠⎞x
另 T = d t T = dt T=dt
= ∑ T = 1 n ( ∑ i = 1 n T i k ) x T k x ∑ d ∣ T d μ ( T d ) f ( d ) = \sum\limits_{T = 1} ^{n}\left( \sum_{i = 1} ^{\frac{n}{T}}i ^ k \right) ^ x T ^ {kx} \sum_{d\mid T}d \mu(\frac{T}{d})f(d) =T=1∑n⎝⎛i=1∑Tnik⎠⎞xTkxd∣T∑dμ(dT)f(d)
最后我们只要先预处理出 T k x ∑ d ∣ T d μ ( T d ) f ( d ) T ^ {kx} \sum_{d\mid T}d \mu(\frac{T}{d})f(d) Tkx∑d∣Tdμ(dT)f(d),就能就简简单单的进行除法分块了。
/*
Author : lifehappy
*/
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include
#define mp make_pair
#define pb push_back
#define endl '\n'
#define mid (l + r >> 1)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define ls rt << 1
#define rs rt << 1 | 1
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const double pi = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
inline ll read() {
ll f = 1, x = 0;
char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f * x;
}
const int N = 2e5 + 10, mod = 1e9 + 7;
int mu[N];
ll sum1[N], sum2[N], sum3[N], f[N], k, x;
bool st[N];
vector<int> prime;
ll quick_pow(ll a, ll n, ll mod) {
ll ans = 1;
while(n) {
if(n & 1) ans = ans * a % mod;
a = a * a % mod;
n >>= 1;
}
return ans;
}
void mobius() {
f[1] = st[0] = st[1] = mu[1] = 1;
for(int i = 2; i < N; i++) {
f[i] = 1;
if(!st[i]) {
prime.pb(i);
mu[i] = -1;
}
for(int j = 0; j < prime.size() && i * prime[j] < N; j++) {
st[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
mu[i * prime[j]] = -mu[i];
}
}
for(int i = 2; i * i < N; i++) {
for(int j = i * i; j < N; j += i * i) {
f[j] = 0;
}
}
for(int i = 1; i < N; i++) {
for(int j = i; j < N; j += i) {
sum3[j] = (sum3[j] + i * mu[j / i] % mod * f[i] % mod + mod) % mod;
}
}
for(int i = 1; i < N; i++) {
ll temp = quick_pow(i, k, mod);
sum1[i] = (sum1[i - 1] + temp) % mod;
sum2[i] = (sum2[i - 1] + quick_pow(temp, x, mod) * sum3[i] % mod) % mod;
}
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T = read();
k = read(), x = read();
mobius();
while(T--) {
ll n = read(), ans = 0;
for(ll l = 1, r; l <= n; l = r + 1) {
r = n / (n / l);
ans = (ans + quick_pow(sum1[n / l], x, mod) * (sum2[r] - sum2[l - 1]) % mod) % mod;
}
cout << (ans % mod + mod) % mod << endl;
}
return 0;
}