5031. 【NOI2017模擬3.27】B 暫存
阿新 • • 發佈:2020-08-01
#include <cstdio> #define N 100000 #define mo 1000000007 #define ll long long #define mem(x, a) memset(x, a, sizeof x) #define mpy(x, y) memcpy(x, y, sizeof y) #define fo(x, a, b) for (int x = (a); x <= (b); x++) #define fd(x, a, b) for (int x = (a); x >= (b); x--) #define go(x) for (int p = tail[x], v; p; p = e[p].fr) using namespace std; int T, n, K, pri[N], tot = 0; int a[N + 10], siz[N + 10], rem[N + 10]; ll g[N + 10], jc[N + 10], ny[N + 10], sl[N + 10]; bool tag[N + 10]; inline int read() { int x = 0, f = 0; char c = getchar(); while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar(); while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? -x : x; } ll ksm(ll x, int y) { ll s = 1; while (y) { if (y & 1) s = s * x % mo; x = x * x % mo, y >>= 1; } return s; } ll C(int x, int y) {return jc[y] * ny[x] % mo * ny[y - x] % mo;} void prepare() { jc[0] = ny[0] = 1; fo(i, 1, N) jc[i] = jc[i - 1] * i % mo; ny[N] = ksm(jc[N], mo - 2); fd(i, N - 1, 1) ny[i] = ny[i + 1] * (i + 1) % mo; siz[1] = 1; fo(i, 2, N) { if (! tag[i]) pri[++tot] = i, siz[i] = rem[i] = 1; fo(j, 1, tot) { if (i * pri[j] > N) break; tag[i * pri[j]] = 1; if (i % pri[j]) siz[i * pri[j]] = 1, rem[i * pri[j]] = i; else siz[i * pri[j]] = siz[i] + 1, rem[i * pri[j]] = rem[i]; } } } int main() { freopen("b.in", "r", stdin); freopen("b.out", "w", stdout); prepare(); T = read(); while (T--) { n = read(), K = read(); fo(i, 1, n) a[i] = read(); g[1] = a[1]; sl[1] = 1; fo(i, 2, n) sl[i] = sl[rem[i]] * C(K - 1, K + siz[i] - 1) % mo; fo(ik, 1, n) fo(j, 1, n / ik) g[ik * j] = (g[ik * j] + g[ik] * sl[j]) % mo; fo(i, 1, n) printf("%lld ", g[i]); puts(""); } return 0; }