Knowledge 1:
Ferma's theorem is an important theorem in number theory. The content of this theorem is: if p is a prime number and (a, p) = 1, then a ^ (p-1) 1_1 (mod p) if p is a prime number and a and p are mutually qualitative, then the remainder of a (p-1-level) divided by p is invariably equal to 1.
We also need to use the Fermat Theorem for Division modulo: a ^ (p-1) % p = 1;-> a ^ (p-2) % p = (1/) % p;
Clever 1:
For (int I = 1; I <= n; I ++)
{Int temp; scanf ("% d", & temp); sum1 [temp] ++ ;}
For (int j = I; j <= m; j + = I) sum + = sum1 [j];
Determine whether there is a multiple. ORZ !!!
Use this piece of code, so that when we traverse from 1 to m, the speed increases very quickly, and then it will not time out.
# Include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <ctime> # include <iostream> # include <algorithm> # include <string> # include <queue> # include <set> # include <map> # include <vector> # include <assert. h> using namespace std; # define lowbit (I) (I &-I) # define sqr (x) * (x )) # define enter printf ("\ n") # define is_sqr (x) (x & (x-1) # define pi acos (-1.0) # Define clr (x) memset (x, 0, sizeof (x) # define fp1 freopen ("in.txt", "r", stdin) # define fp2 freopen ("out.txt", "w", stdout) # define pb push_back typedef _ int64 LL; const double eps = 1e-7; const double DINF = 1e100; const int INF = 1000000006; const ll linf = 000000000000000005ll; const int MOD = (int) 1e9 + 7; const int maxn = 300005; template <class T> inline T Min (T a, T B) {return a <B? A: B;} template <class T> inline T Max (T a, T B) {return a> B? A: B;} template <class T> inline T Min (T a, T B, T c) {return min (a, B), c );} template <class T> inline T Max (T a, T B, T c) {return max (a, B), c);} LL f [maxn], e [maxn], a [maxn], ans [maxn], sum1 [maxn]; LL quick_pow (LL a, LL B) // B power of, fast Power modulo {LL ret = 1; while (B) {if (B & 1) ret = (ret * a) % MOD; B/= 2; a = (a * a) % MOD;} return ret % MOD;} LL cal (LL n, LL k) {if (k = 0 | n = k) return 1; return (f [n] * e [k] % MOD) * e [n-k] % MOD; // note Operation Sequence} // some variables do not use C99 in the future. int main () {f [0] = e [0] = 1; for (int I = 1; I <= maxn; I ++) {f [I] = f [I-1] * I % MOD; e [I] = quick_pow (f [I], MOD-2);} int n, m, k; while (scanf ("% d", & n, & m, & k )! = EOF) {clr (sum1); for (int I = 1; I <= n; I ++) {int temp; scanf ("% d", & temp ); sum1 [temp] ++;} for (int I = m; I> = 1; I --) // do not perform the m/I cycle every time when writing backwards {int sum = 0; for (int j = I; j <= m; j + = I) sum + = sum1 [j]; if (sum <n-k) // k values are different, and n-k values are the same. {Ans [I] = 0; continue;} ans [I] = (cal (sum, n-k) * quick_pow (m/I-1, sum-(n-k) % MOD) * quick_pow (m/I, n-sum) % MOD; for (int j = 2 * I; j <= m; j + = I) ans [I] = (ans [I]-ans [j] + MOD) % MOD;} for (int I = 1; I <m; I ++) printf ("% lld", ans [I]); printf ("% lld \ n", ans [m]);} return 0 ;} # include <cstdio> # include <cstdlib> # include <cstring> # include <cmath> # include <ctime> # include <iostream> # include <algorithm> # include <s Tring> # include <queue> # include <set> # include <map> # include <vector> # include <assert. h> using namespace std; # define lowbit (I) (I &-I) # define sqr (x) * (x )) # define enter printf ("\ n") # define is_sqr (x) (x & (x-1) # define pi acos (-1.0) # define clr (x) memset (x, 0, sizeof (x) # define fp1 freopen ("in.txt", "r", stdin) # define fp2 freopen ("out.txt", "w ", stdout) # define pb push_backtypedef _ int64 LL; const double eps = 1e-7; const double DINF = 1e100; const int INF = 1000000006; const ll linf = 000000000000000005ll; const int MOD = (int) 1e9 + 7; const int maxn = 300005; template <class T> inline T Min (T a, T B) {return a <B? A: B;} template <class T> inline T Max (T a, T B) {return a> B? A: B;} template <class T> inline T Min (T a, T B, T c) {return min (a, B), c );} template <class T> inline T Max (T a, T B, T c) {return max (a, B), c);} LL f [maxn], e [maxn], a [maxn], ans [maxn], sum1 [maxn]; LL quick_pow (LL a, LL B) // B power of, fast Power modulo {LL ret = 1; while (B) {if (B & 1) ret = (ret * a) % MOD; B/= 2; a = (a * a) % MOD;} return ret % MOD;} LL cal (LL n, LL k) {if (k = 0 | n = k) return 1; return (f [n] * e [k] % MOD) * e [n-k] % MOD; // note the Operation Sequence} // In the future, some variables still do not use C99 in writing int main () {f [0] = e [0] = 1; for (int I = 1; I <= maxn; I ++) {f [I] = f [I-1] * I % MOD; e [I] = quick_pow (f [I], MOD-2);} int n, m, k; while (scanf ("% d", & n, & m, & k )! = EOF) {clr (sum1); for (int I = 1; I <= n; I ++) {int temp; scanf ("% d", & temp ); sum1 [temp] ++;} for (int I = m; I> = 1; I --) // do not perform the m/I cycle every time when writing backwards {int sum = 0; for (int j = I; j <= m; j + = I) sum + = sum1 [j]; if (sum <n-k) // k values are different, and n-k values are the same. {Ans [I] = 0; continue;} ans [I] = (cal (sum, n-k) * quick_pow (m/I-1, sum-(n-k) % MOD) * quick_pow (m/I, n-sum) % MOD; for (int j = 2 * I; j <= m; j + = I) ans [I] = (ans [I]-ans [j] + MOD) % MOD;} for (int I = 1; I <m; I ++) printf ("% lld", ans [I]); printf ("% lld \ n", ans [m]);} return 0 ;}