GMOJ 5031. 【NOI2017模拟3.27】B
Description
Input
Output
Sample Input
2
6 2
2 3 3 3 3 3
23 3
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
Sample Output
2 7 7 15 7 23
2 9 9 24 9 39 9 50 24 39 9 102 9 39 39 90 9 102 9 102 39 39 9
Data Constraint
f的范围为0到10^9+7-1
Solution
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 500000
#define Mod 1000000007
#define fo(i, a, b) for(int i = a; i <= b; i ++)
#define Mes(a, b) memset(a, b, sizeof a)
void read(int &x) {
char ch = getchar(); x = 0;
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
}
int f[N + 1], g[N + 1], h[N + 1];
int n, k;
int main() {
freopen("b.in", "r", stdin);
freopen("b.out", "w", stdout);
int T; read(T);
while (T --) {
read(n), read(k);
fo(i, 1, n) read(f[i]);
fo(i, 1, n) g[i] = 1;
while (k) {
if (k & 1) {
Mes(h, 0);
fo(i, 1, n) fo(j, 1, n / i) (h[i * j] += 1ll * f[i] * g[j] % Mod) %= Mod;
fo(i, 1, n) f[i] = h[i];
}
Mes(h, 0);
fo(i, 1, n) fo(j, 1, n / i) (h[i * j] += 1ll * g[i] * g[j] % Mod) %= Mod;
fo(i, 1, n) g[i] = h[i];
k >>= 1;
}
fo(i, 1, n) printf("%d ", f[i]);
puts("");
}
return 0;
}