#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include inline int fact_mod(int n, int mod) { using ll = long long; using ull = unsigned long long; unsigned inv = 1; for (int i = 0; i < 5; ++i) inv *= 2 - inv * unsigned(mod); int r2 = -ull(mod) % mod; // 仮定: x < mod * 2^32 auto reduce = [&] (ull x) { ull y = ull(unsigned(x) * inv) * mod; return int(x >> 32) + mod - int(y >> 32); // (0, 2 * mod) // [0, mod) に制限する場合は、上の行を以下のように変更する。 // int ret = int(x >> 32) - int(y >> 32); // return ret < 0 ? ret + mod : ret; }; auto init = [&] (int n) { return reduce(ll(n) * r2); }; auto add_mod = [&] (int a, int b) { return (a += b - mod) < 0 ? a + mod : a; }; const int M = 24; const int diff = init(M); int fact[M], mult[M]; for (int i = 0; i < M; ++i) fact[i] = init(1); for (int i = 0; i < M; ++i) mult[i] = init(i + 1); for (int i = 0; i < n / M; ++i) { for (int j = 0; j < M; ++j) fact[j] = reduce(ll(fact[j]) * mult[j]); for (int j = 0; j < M; ++j) mult[j] = add_mod(mult[j], diff); } int ret = init(1); for (int i = 0; i < M; ++i) { ret = reduce(ll(ret) * fact[i]); } ret = reduce(ret); for (int i = n / M * M + 1; i <= n; ++i) { ret = ll(ret) * i % mod; } return ret; } int main() { const int mod = 1e9 + 7; int n; scanf("%d",&n); printf("%d\n", fact_mod(n, mod)); return 0; }