1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| #include <bits/stdc++.h> using namespace std; const int maxn = 310000; const int mod = 1000000007; int n, m, k; int prime[maxn], tot, mu[maxn]; bool vis[maxn]; long long fac[maxn], rev[maxn]; long long F[maxn], f[maxn]; int a[maxn]; int cnt[maxn]; long long extend_gcd(long long a, long long b, long long &x, long long &y) { if (a == 0 && b == 0) return -1; if (b == 0) { x = 1; y = 0; return a; } long long d = extend_gcd(b, a % b, y, x); y -= a / b * x; return d; } long long mod_rev(long long a, long long n) { long long x, y; long long d = extend_gcd(a, n, x, y); if (d == 1) return (x % n + n) % n; else return -1; }
void init() { tot = 0; mu[1] = 1; for (int i = 2; i < maxn; i++) { if (!vis[i]) { prime[tot++] = i; mu[i] = -1; } for (int j = 0; j < tot; j++) { if (i * prime[j] >= maxn) break; vis[i * prime[j]] = 1; if (i % prime[j] == 0) { mu[i * prime[j]] = 0; break; } else { mu[i * prime[j]] = -mu[i]; } } } fac[0] = rev[0] = 1; for (int i = 1; i < maxn; i++) { fac[i] = fac[i - 1] * i % mod; rev[i] = mod_rev(fac[i], mod); } }
long long quick_mod(long long a, long long b) { long long ans = 1; a %= mod; while (b) { if (b & 1) { ans = ans * a % mod; b--; } b >>= 1; a = a * a % mod; } return ans; }
long long Lucas(long long m, long long n) { if (n == 0) return 1; long long ans = fac[m] * rev[n] % mod * rev[m - n] % mod; return ans; }
int main() { init(); while (scanf("%d%d%d", &n, &m, &k) != EOF) { memset(cnt, 0, sizeof cnt); memset(f, 0, sizeof f); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); cnt[a[i]]++; } for (int i = 1; i <= m; i++) for (int j = i + i; j <= m; j += i) cnt[i] += cnt[j];
for (int i = 1; i <= m; i++) { long long p = cnt[i]; if (k - n + p < 0) { F[i] = 0; continue; } F[i] = Lucas(p, k - n + p) * quick_mod(m / i - 1, k - n + p) % mod * quick_mod(m / i, n - p) % mod; }
for (int i = 1; i <= m; i++) { if (F[i] == 0) f[i] = 0;
else for (int j = i; j <= m; j += i) { f[i] += mu[j / i] * F[j]; f[i] %= mod; } printf("%lld", (f[i] + mod) % mod); if (i != m) printf(" "); } printf("\n"); } return 0; }
|