text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; int n; long long jc[1000005]; long long qsm(long long x, long long y) { long long a = 1; long long base = x; while (y > 0) { if (y & 1) { a = (a * base) % 1000000007; } y >>= 1; base = (base * base) % 1000000007; } return a; } int main() { cin >> n; jc[1] = 1; for (int i = 2; i <= n; i++) { jc[i] = (jc[i - 1] * i) % 1000000007; } long long ans; ans = (jc[n] - qsm(2, n - 1) + 1000000007) % 1000000007; cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int mod = 1e9 + 7; int n; cin >> n; long long unimodal_perms = 1; for (int i = 1; i < n; i++) { unimodal_perms = (unimodal_perms * 2) % mod; } long long fact = 1; for (int i = 1; i <= n; i++) { fact = (fact * i) % mod; } cout << (fact - unimodal_perms + mod) % mod; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, mod = 1e9 + 7, ans = 1; long long fastpow(long long x, long long y) { long long ans = 1; while (y) { if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } int main() { cin >> n; for (int i = 1; i <= n; i++) ans = ans * i % mod; cout << (ans - fastpow(2, n - 1) + mod) % mod; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin >> n; long long f = 1; long long m = 1; for (long long i = 1; i < n + 1; i++) f = (f * i) % 1000000007; for (long long i = 1; i < n; i++) m = (m * 2) % 1000000007; cout << ((f - m + 1000000007) % 1000000007 + 1000000007) % 1000000007; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; long long int f = 1, f1 = 1; for (long long int i = 1; i <= n; i++) { f *= i; f %= (1000000007); } for (long long int i = 1; i < n; i++) { f1 *= 2; f1 %= (1000000007); } long long int ans = (f - f1); if (ans < 0) ans += (1000000007); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f3f3f3f3f; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void zz() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } const long long mx = 1e6 + 6; long long fact[mx + 5]; long long power(long long a, long long n) { if (!n) return 1; long long pt = power(a, n / 2); pt *= pt, pt %= 1000000007; if (n & 1) pt *= a, pt %= 1000000007; return pt; } int32_t main() { zz(); fact[0] = fact[1] = 1; for (long long i = 2; i < mx; i++) { fact[i] = i * fact[i - 1]; fact[i] %= 1000000007; } long long n; cin >> n; long long ans = fact[n]; ans -= power(2, n - 1); ans = (ans + 1000000007) % 1000000007; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t e = pow(10, 9) + 7; int64_t n, l, m, i, prod = 1, com = 1; cin >> n; for (i = 1; i <= n; i++) { prod = prod * i; if (prod > e) prod %= e; } for (i = 1; i < n; i++) { com *= 2; if (com > e) com %= e; } if (prod >= com) cout << prod - com; else cout << prod + e - com; return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int fact(int n) { long long ans = n; for (int i = n - 1; i > 0; --i) { ans = (ans * i) % MOD; } return ans; } int pow2(int n) { long long ans = 1, b = 2; while (n > 0) { if (n % 2) { ans = (ans * b) % MOD; } b = (b * b) % MOD; n /= 2; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; cout << (fact(n) - pow2(n - 1) + MOD) % MOD; }
#include <bits/stdc++.h> using ll = long long; int const nmax = 1000000; int const modulo = 1000000007; int lgpow(int a, int b) { if (b == 0) return 1; else if (b == 1) return a; else { int result = lgpow(a, b / 2); if (b % 2 == 0) return 1LL * result * result % modulo; else return 1LL * result * result % modulo * a % modulo; } } int main() { int n; std::cin >> n; int result = 1, result2 = 1; for (int i = 1; i <= n; i++) result = 1LL * result * i % modulo; std::cout << (modulo + result - lgpow(2, n - 1)) % modulo; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double EPS = 1e-9; const long double PI = acos(-1); const long long INF = 1e18; const long long mod = 1e9 + 7; long long factorial(long long n) { if (n == 0) return 1; long long x = 1; for (long long i = 1; i <= n; i++) { x = (x * i) % mod; } return x; } long long power(long long x, long long y) { long long res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; x = (x * x) % mod; y = y >> 1; } return res % mod; } long long modInverse(long long n) { return power(n, mod - 2); } long long nCr(long long n, long long r) { if (n < r) return 0; if (r == 0) return 1; return ((factorial(n) % mod) * (modInverse(((factorial(r) % mod) * (factorial(n - r) % mod)) % mod) % mod) % mod); } long long xor_1_x(long long x) { if (x % 4 == 0) return x; if (x % 4 == 1) return 1; if (x % 4 == 2) return x + 1; return 0; } bool prime(long long n) { if (n < 2) return false; for (long long x = 2; x * x <= n; x++) { if (n % x == 0) return false; } return true; } vector<long long> factors(long long n) { vector<long long> f; for (long x = 2; x * x <= n; x++) { while (n % x == 0) { f.push_back(x); n /= x; } } if (n > 1) f.push_back(n); return f; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int test_cases = 1; while (test_cases--) { long long n; cin >> n; long long ans = ((factorial(n) % mod) - (power(2, n - 1) % mod)) % mod; if (ans < 0) ans += mod; cout << ans << endl; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1000 * 1000, MOD = 1000 * 1000 * 1000 + 7; int main() { int dp[MAX_N + 1]; long long fact = 6; dp[3] = 2; for (int i = 4; i <= MAX_N; ++i) { dp[i] = ((i - 2) * fact % MOD + 2 * dp[i - 1] % MOD) % MOD; fact *= i; fact %= MOD; } int n; cin >> n; cout << dp[n] << endl; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") const double PI = acos(-1.0); using namespace std; const double EPS = 1e-9; const int N = 5e5 + 9; long long n, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; long long a = 1; for (int i = 1; i <= n; i++) { a *= 1LL * i; a %= mod; } long long b = 1; for (int i = 1; i <= n - 1; i++) { b *= 2LL; b %= mod; } cout << (a - b + mod) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, breh = 1e9 + 7; cin >> n; long long fact = 1; for (long long i = 1; i <= n; i++) { fact *= i; fact %= breh; } long long sum = n, f1 = n - 1; sum = 1; for (long long i = 0; i < n - 1; i++) { sum *= 2; sum %= breh; } fact %= breh; fact -= sum; fact %= breh; if (fact < 0) fact += breh; cout << fact << endl; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000; const int mod = 1000000007; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); long long n; cin >> n; long long now = 1; long long total = 1; for (int i = 0; i < n - 1; i++) { now *= 2; now %= mod; total *= i + 2; total %= mod; } long long ans = (total - now + mod) % mod; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX = 2e6 + 5; const int MAXN = 105; long long pw(long long a, long long n) { long long rs = 1; while (n) { if (n & 1) rs = ((rs % 1000000007) * (a % 1000000007)) % 1000000007; n >>= 1; a = ((a % 1000000007) * (a % 1000000007)) % 1000000007; } return rs; } long long dp[MAX]; int main() { long long n; cin >> n; long long an = 1; dp[0] = 1; dp[1] = 1; dp[2] = 2; for (long long i = 2; i <= n; i++) { an = (an % 1000000007 * i % 1000000007) % 1000000007; dp[i] = an; } an -= pw(2, n - 1); an += 1000000007; an %= 1000000007; cout << an << endl; }
#include <bits/stdc++.h> using namespace std; long long pow2(long long a, long long b, long long m) { long long ans = 1; while (b > 0) { if (b & 1) { ans = (ans * a) % m; } a = (a * a) % m; b >>= 1; } return ans; } long long inv(long long a, long long b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; } long long* fact = new long long[1000005]{0}; void solve() { long long n; cin >> n; long long ans = fact[n]; long long mul = fact[n - 1]; for (long long i = 2; i < n; i++) { long long c = (inv(fact[i - 1], 1000000007) * mul) % 1000000007; c = (c * inv(fact[n - i], 1000000007)) % 1000000007; ans = (ans - (c) % 1000000007 + 1000000007) % 1000000007; } cout << ans - 2 << "\n"; } int32_t main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); fact[0] = fact[1] = 1; for (long long i = 2; i < 1000002; i++) { fact[i] = (fact[i - 1] * i) % 1000000007; } long long t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long fact[1000005]; long long ans[1000006]; int main() { long long n; cin >> n; fact[0] = 1; for (long long i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % 1000000007; ans[3] = 2; for (long long i = 4; i <= n; i++) { ans[i] = ((ans[i - 1] * i) % 1000000007 + ((fact[i - 1] - ans[i - 1]) * (i - 2)) % 1000000007 + 1000000007) % 1000000007; } cout << ans[n] << endl; }
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; void solve() { long long n; cin >> n; long long res1 = 1, res2 = 1; for (int i = 1; i <= n; i++) { res1 *= i; res1 %= mod; if (i != n) { res2 *= 2; res2 %= mod; } } long long ans = res1 - res2; if (ans < 0) ans += mod; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 3e5 + 9; void solve() { long long n; cin >> n; long long ans = 1; long long ex = 1; for (long long i = 1; i <= n; i++) ans = (ans * i) % mod; for (long long i = 2; i <= n; i++) ex = (ex * 2) % mod; cout << (ans - ex + mod) % mod << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long fact(long long a) { if (a == 1) return 1; else return (a * fact(a - 1)) % mod; } long long po(long long n) { if (n == 1) return 2; return (2 * po(n - 1)) % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long g = fact(n); g = ((g - po(n - 1)) + mod) % mod; cout << g << "\n"; }
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res % 1000000007; } long long modInverse(long long n, long long p) { return power(n, p - 2, 1000000007); } long long nCrModPFermat(long long n, long long r, long long p) { if (r == 0) return 1; long long fac[n + 1]; fac[0] = 1; for (long long x = 1; x <= n; x++) fac[x] = ((x % 1000000007) * ((long long)(fac[x - 1]) % 1000000007)) % 1000000007; return ((long long)(((long long)fac[n] * modInverse(fac[r], p)) % 1000000007) % p * modInverse(fac[n - r], p) % p) % p; } signed main() { long long n; cin >> n; map<long long, long long> fact; fact[1] = 1; fact[0] = 1; for (long long x = 2; x <= n; x++) { fact[x] = ((x % 1000000007) * ((long long)(fact[x - 1]) % 1000000007)) % 1000000007; } long long ans = 0; cout << (((fact[n] + 1000000007) % 1000000007) - ((power(2, n - 1, 1000000007) % 1000000007) % 1000000007) + 1000000007) % 1000000007 << "\n"; }
#include <bits/stdc++.h> using namespace std; long long int hell = pow(10, 9) + 7; void solve() { long long int n; cin >> n; long long int a = 1, b = 1; for (long long int i = 1; i <= n; i++) { a = (i * a) % hell; if (i < n) b = (b * 2) % hell; } a = (a - b + hell) % hell; cout << a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t z = clock(); long long int qc = 1; for (long long int i = 1; i <= qc; i++) { solve(); } fprintf(stderr, "Total Time:%.4Lf\n", (long double)(clock() - z) / CLOCKS_PER_SEC), fflush(stderr); }
#include <bits/stdc++.h> using namespace std; long long fact(long long n) { long long ans = 1; for (long long i = 2; i <= n; i++) ans = (ans * i) % 1000000007; return ans; } long long power(long long a, long long b) { long long x = 1; for (long long i = 1; i <= b; i++) x = (x * a) % 1000000007; return x; } int main() { long long n; cin >> n; cout << (fact(n) - power(2, n - 1) + 1000000007) % 1000000007; }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; struct node { int num; int v; long long w; }; struct cmp1 { bool operator()(node x, node y) { return x.num < y.num; } }; priority_queue<node, vector<node>, cmp1> q1; const int Maxn = 100 + 10; const long long mod = 1000000000 + 7; long long gcd(long long a, long long b) { long long c; c = a % b; while (c) { a = b; b = c; c = a % b; } return b; } long long fpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } int main() { long long n; scanf("%lld", &n); long long sum = 1; for (long long i = 2; i <= n; i++) { sum *= i; sum %= mod; } long long temp = fpow(2, n - 1) % mod; sum -= temp; sum += mod; printf("%lld\n", sum % mod); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; int factorial(long long n) { long long out = n; for (int i = 2; i < n; i++) { out *= i; out %= MOD; } return out; } int pow(int base, long long exp) { long long out = 1; for (int i = 0; i < exp; i++) { out *= base; out %= MOD; } return out; } int main() { long long n; cin >> n; n = factorial(n) - pow(2, n - 1); n = n < 0 ? n + MOD : n; cout << n << endl; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { int n; scanf("%d", &n); long long ans = 2; for (int i = 2; i <= n - 1; ++i) { ans = 2 * ans % mod; } long long fac = 1; for (int i = 1; i <= n; ++i) { fac = fac * i % mod; } ans = ((fac - ans) % mod + mod) % mod; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 5, N = 1e2 + 5, mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); long long n; cin >> n; long long ans = 1; for (long long i = 2; i <= n; i++) { ans = (ans * i) % mod; } long long qurwa = 2; for (long long i = 3; i <= n; i++) { qurwa = (qurwa * 2) % mod; } cout << ((ans + mod) - qurwa) % mod << endl; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long MOD = 1e9 + 7; long long powerMOD(long long x, long long y) { if (y == 0) return 1; if (y & 1) return (x * powerMOD(x, y - 1)); long long t = powerMOD(x, y / 2) % MOD; return (t * t) % MOD; } void solve() { long long n; cin >> n; long long ans = 0; long long res = 1; for (long long i = 1; i <= n; i++) { res = (res * i) % MOD; } res = res % MOD; long long p = powerMOD(2, n - 1) % MOD; ans = (res - p + MOD) % MOD; cout << ans << '\n'; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; const int M = 1e9 + 7; int n; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; long long ans = 1; for (int i = (1); i < (n + 1); i++) { ans = (ans * i) % M; } long long pow2 = 1; for (int i = (0); i < (n - 1); i++) { pow2 = (2 * pow2) % M; } ans = (ans - pow2) % M; ans = (ans + M) % M; cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int p = 1e9 + 7; int n, t; long long qpow(long long a, long long n, long long p) { long long ans = 1; while (n) { if (n & 1) ans *= a, ans %= p; a *= a, a %= p; n >>= 1; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; long long ans = 1; for (int i = (1); i <= (n); ++i) { (ans *= i) %= p; } long long vv = qpow(2, n - 1, p); ans = (ans + p - vv) % p; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vi = vector<ll>; using vvi = vector<vector<ll> >; using vpi = vector<pair<ll, ll> >; using pi = pair<ll, ll>; using st = set<ll>; using stk = stack<ll>; using kiwi = queue<ll>; using mp = map<ll, ll>; using ump = unordered_map<ll, ll>; const ll mx = 1e5 + 123; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; ll n; cin >> n; ll pw = 1, ans = 1; for (ll i = 2; i <= n; ++i) ans = ans * i % 1000000007, pw = pw * 2 % 1000000007; cout << (ans - pw + 1000000007) % 1000000007 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long fact = 1; long long prod = 1; for (long long i = 1; i <= n - 1; i++) { prod *= 2; fact *= i; prod %= 1000000007; fact %= 1000000007; } fact *= n; fact %= 1000000007; fact -= prod; fact %= 1000000007; if (fact < 0) fact += 1000000007; cout << fact << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double delta = 0.0000000001; const double pi = 3.1415926535; void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long int powM(long long int x, long long int y, long long int m) { long long int ans = 1, r = 1; x %= m; while (r > 0 && r <= y) { if (r & y) { ans *= x; ans %= m; } r <<= 1; x *= x; x %= m; } return ans; } int main() { FAST(); long long int n, k = 1000000007; cin >> n; long long int ans = 1; for (long long int i = 1; i < n; i++) { ans = (ans * ((i + 1) % k)) % k; } long long int temp; temp = powM(2, n - 1, k); ans = (ans - temp) % k; if (ans >= 0) cout << ans; else cout << k + ans; }
#include <bits/stdc++.h> using namespace std; int main() { int mod = 1000000007; int n; cin >> n; long long a = 1, b = 1; for (int i = 2; i <= n; i++) { a = (a * i) % mod; b = (b * 2) % mod; } cout << (a - b + mod) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long mod = 10e8 + 7; long long n; cin >> n; long long ans = 1; for (int i = 2; i < n + 1; i++) { ans *= i % mod; ans %= mod; } long long nonc = 2; for (int i = 1; i < n - 1; i++) { nonc *= 2 % mod; nonc %= mod; } cout << (ans - nonc + mod) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int xx[4] = {0, 0, 1, -1}; int yy[4] = {-1, 1, 0, 0}; long long mod = 1000000007; int main() { long long n; scanf("%lld", &n); long long fact = 1; for (long long i = 2; i <= n; i++) { fact = (fact % mod * i % mod) % mod; } long long powr = 1; for (long long i = 1; i <= n - 1; i++) powr = (powr % mod * 2) % mod; fact = fact % mod; powr = powr % mod; long long ans = (fact - powr) % mod; long long fres = (ans < 0) ? (ans + mod) : ans; cout << fres << endl; }
#include <bits/stdc++.h> using namespace std; long long fact(long long n) { long long f = 1; for (long long i = 2; i <= n; i++) { f = (f * i) % 1000000007; } return f; } long long power(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res = (res % 1000000007 * a % 1000000007) % 1000000007; } a = (a % 1000000007 * a % 1000000007) % 1000000007; b = b / 2; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long val = fact(n); long long temp = power(2, n - 1); cout << (val - temp + 1000000007) % 1000000007 << "\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; const ll mod = 1e9 + 7; ll js(ll n) { ll ret = 1; while (n) ret = ret * n % mod, n--; return ret; } ll pow2(ll n) { ll ret = 1; while (n) ret = ret * 2 % mod, n--; return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll T = 1; while (T--) { ll n; cin >> n; ll ret = js(n) - pow2(n - 1); cout << (ret % mod + mod) % mod << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int ans = 1; for (int i = 2; i <= n; ++i) { ans = 1LL * ans * i % M; } int two = 1; for (int i = 1; i < n; ++i) { two = (two + two) % M; } cout << (ans - two + M) % M << "\n"; }
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const double PI = 3.1415926535897932384626433832795028841; const int mov_x[] = {0, 0, 1, -1}; const int mov_y[] = {1, -1, 0, 0}; int main() { long long n, i; cin >> n; vector<long long> F(n + 1), P(n + 1); F[0] = 1; P[0] = 1; for (i = 1; i < n + 1; i++) F[i] = (F[i - 1] * i) % M; for (i = 1; i < n + 1; i++) P[i] = (P[i - 1] * 2) % M; cout << (F[n] - P[n - 1] + M) % M << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; long long n; int main() { cin >> n; long long x = 1; long long y = 1; for (long long i = 1; i <= n; i++) { x = x * i % 1000000007; if (i != 1) y = y * 2 % 1000000007; } cout << (x - y + 1000000007) % 1000000007 << endl; }
#include <bits/stdc++.h> using namespace std; bool prime[1000005]; void SieveOfEratosthenes() { memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= 1000005; p++) { if (prime[p] == true) { for (int i = p * p; i <= 1000005; i += p) prime[i] = false; } } } string toLower(string s) { for (int i = 0; i < s.size(); i++) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] + 32; return s; } long long int modC(long long int n) { n--; long long int val = 1; while (n--) { val = val * 2; val = val % 1000000007; } return val % 1000000007; } int main() { long long int n; cin >> n; long long int i, val = 1; for (i = 1; i <= n; i++) { val = val * i; val = val % 1000000007; } long long int ex = modC(n); if (ex > val) cout << (val - ex) % 1000000007 + 1000000007 << "\n"; else cout << (val - ex) % 1000000007 << "\n"; }
#include <bits/stdc++.h> using namespace std; long long fact(long long n) { long long f = 1; for (long long i = 1; i <= n; i++) { f = (f * i) % 1000000007; } return f; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; long long r = fact(n); long long q = 1; n--; while (n > 0) { q = (q * 2) % 1000000007; n--; } long long ans = r - q; if (ans < 0) { ans = 1000000007 + ans; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> int main() { int n; std::cin >> n; long long int ans = 1; long long int mod = (long long int)(1e9 + 7); for (int i = 1; i <= n; i++) { ans = (ans * i) % mod; } long long int sub = 1; for (int i = 1; i < n; i++) { sub = (sub * 2) % mod; } ans = ((ans - sub) % mod + mod) % mod; std::cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, fact = 1, acy = 1, i; cin >> n; int p = 1000000007; for (i = 1; i <= n; i++) { fact = (fact % p * i % p) % p; } for (i = 1; i <= n - 1; i++) { acy = ((acy % p) * 2) % p; } fact %= p; fact = fact - acy; fact %= p; if (fact < 0) fact += p; cout << fact; return 0; }
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b) { return ((a % 1000000007) + (b % 1000000007)) % 1000000007; } inline long long mul(long long a, long long b) { return ((a % 1000000007) * (b % 1000000007)) % 1000000007; } inline long long sub(long long a, long long b) { return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007; } const long long N = 1e6 + 7; long long fac[N]; void pre() { fac[0] = 1; fac[1] = 1; for (long long i = 2; i < N - 5; i++) fac[i] = mul(i, fac[i - 1]); } long long power(long long x, unsigned long long y, long long p = 1000000007) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res % p; } void solve() { long long n; cin >> n; long long ans = fac[n]; ans = sub(ans, power(2, n - 1)); cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); pre(); long long t = 1; for (long long a = 0; a < t; a++) { solve(); } }
#include <bits/stdc++.h> using namespace std; long long f[1000005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); f[0] = 1; for (int i = 1; i < 1000005; i++) { f[i] = f[i - 1] * i; f[i] %= 1000000007; } long long n; cin >> n; long long pwr = 1; for (int i = 1; i < n; i++) { pwr *= 2; pwr %= 1000000007; } long long ans = f[n] - pwr; ans += 1000000007; cout << ans % 1000000007 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int fact[1000001]; long long int pow1[10000001]; long long int mod = 1e9 + 7; int main() { fact[0] = 1; pow1[0] = 1; pow1[1] = 2; fact[1] = 1; for (int i = 2; i <= 1000000; i++) { fact[i] = (fact[i - 1] * i) % mod; pow1[i] = (pow1[i - 1] * 2) % mod; } long long int n; cin >> n; cout << (((fact[n] - pow1[n - 1]) % mod) + mod) % mod; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double eps = 1e-6; const double pi = acos(-1.0); const int maxn = 1e6 + 10; const int N = 3e3 + 5; const long long inf = 0x3f3f3f3f; const int dir[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; long long fac[maxn], inv1[maxn]; long long Pow(long long a, long long b) { long long ans = 1; while (b > 0) { if (b & 1) { ans = ans * a % mod; } a = a * a % mod; b >>= 1; } return ans; } long long inv(long long b) { return Pow(b, mod - 2) % mod; } long long C(long long n, long long m) { if (m > n || n < 0 || m < 0) return 0; if (m == 0 || m == n) return 1; long long res = (fac[n] * inv1[m] % mod * inv1[n - m]) % mod; return res; } void init() { fac[0] = 1; for (int i = 1; i < maxn; i++) { fac[i] = fac[i - 1] * i % mod; } inv1[maxn - 1] = Pow(fac[maxn - 1], mod - 2); for (int i = maxn - 2; i >= 0; i--) { inv1[i] = inv1[i + 1] * (i + 1) % mod; } } long long dp[maxn]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); init(); long long n; cin >> n; dp[3] = 2; for (int i = 4; i <= n; i++) dp[i] = (fac[i] + -Pow(2, i - 1) + mod) % mod; cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; long long int MOD = 1000000007; long long int MOD1 = 998244353; mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count()); unsigned long long power(unsigned long long x, int y, int p) { unsigned long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } void solve() { long long int n; cin >> n; long long int res = 1; for (int i = 1; i <= n; i++) { res = (res * i) % MOD; } long long int p = power(2, n - 1, MOD); res = (res - p + MOD) % MOD; cout << res << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
#include <bits/stdc++.h> using namespace std; template <class T, class V> ostream& operator<<(ostream& s, pair<T, V> a) { s << a.first << ' ' << a.second; return s; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int T = 1; for (int qq = 1; qq <= T; qq++) { int n; cin >> n; vector<long long int> f(n + 1), p(n + 1); f[0] = p[0] = 1; for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % (1000000007), p[i] = p[i - 1] * 2 % (1000000007); long long int ans = 0; for (int i = n; i >= 3; i--) { ans = (ans + f[i - 1] * (i - 2) % (1000000007) * p[n - i] % (1000000007)) % (1000000007); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; void solve() { long long n; cin >> n; long long t = 1; for (long long i = 1; i <= n - 1; i++) { t *= 2; t %= MOD; } long long s = 1; for (long long i = 1; i <= n; i++) { s *= i; s %= MOD; } cout << (s - t + MOD * MOD) % MOD << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0); long long T = 1; while (T--) solve(); }
#include <bits/stdc++.h> using namespace std; int n; const long long Mod = 1e9 + 7; long long calc(int n) { long long ans = 1; for (int i = 1; i <= n; i++) { ans = (ans * i) % Mod; } return ans; } int main() { cin >> n; long long f = calc(n); long long k = 1; for (int i = 1; i <= n - 1; i++) { k = (k * 2) % Mod; } long long ans = f - k; while (ans < 0) { ans += Mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> int read() { register char ch = getchar(); register int ret = 0; while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) { ret = ret * 10 + ch - '0'; ch = getchar(); } return ret; } int n, a[500055], m, sum; long long ans = 1, po = 1; int main() { n = read(); for (register int i = (1); i <= (n); ++i) { ans = ans * i % 1000000007; if (i > 1) po = po * 2 % 1000000007; } printf("%lld", (ans - po + 1000000007) % 1000000007); return 0; }
#include <bits/stdc++.h> const int MOD = 1e09 + 7; using namespace std; int t, n; long long fact; long long ans[1100000]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; ans[3] = 2; fact = 6; for (int i = 4; i <= n; i++) { ans[i] = ans[i - 1] * 2 + fact * (i - 2); ans[i] %= MOD; fact *= i; fact %= MOD; } cout << ans[n] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int mod = (ll)1e9 + 7; const int INF = 1e9 + 1; const int N = 201; const double eps = 1e-3; template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } ll power(ll a, ll b) { if (!b) return 1; ll c = power(a, b / 2); c = (1LL * c * c); if (b % 2) c = (1LL * c * a); return c; } int mul(int a, int b) { return a * 1ll * b % mod; } int add(int a, int b) { int s = (a + b); if (s >= mod) s -= mod; return s; } struct RMQ { vector<vector<int>> st; RMQ(vector<int> &a) { int n = a.size(); int k = ceil(log2(n)); st.clear(); st = vector<vector<int>>(n, vector<int>(k + 1, 0)); for (int i = 0; i < n; ++i) { st[i][0] = a[i]; } for (int j = 1; j <= k; ++j) { for (int i = 0; i + (1 << j) <= n; ++i) { st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); } } } int rng_q(int l, int r) { if (l > r) return -1; int j = log2(r - l + 1); int ans = max(st[l][j], st[r - (1 << j) + 1][j]); return ans; } }; template <long long mod = 1000000007> struct modint { long long a; modint() : a(0) {} modint(long long t) { a = t % mod; if (a < 0) a += mod; } operator long long() const { return a; } bool operator==(const modint &x) const { return a == x.a; } bool operator!=(const modint &x) const { return a != x.a; } modint operator-() const { return modint(a ? (mod - a) : 0); } modint operator~() const { return pow(mod - 2); } modint operator+(const modint &x) const { return modint(*this) += x; } modint operator-(const modint &x) const { return modint(*this) -= x; } modint operator*(const modint &x) const { return modint(*this) *= x; } modint operator/(const modint &x) const { return modint(*this) /= x; } modint &operator+=(const modint &x) { a += x.a; if (a >= mod) a -= mod; return *this; } modint &operator-=(const modint &x) { a -= x.a; if (a < 0) a += mod; return *this; } modint &operator*=(const modint &x) { a = a * x.a % mod; return *this; } modint &operator/=(const modint &x) { a = a * (~x).a % mod; return *this; } friend ostream &operator<<(ostream &os, const modint &x) { return os << x.a; } friend istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = modint(t); return is; } modint pow(long long x) const { modint ret = 1, tmp = a; for (; x; tmp *= tmp, x >>= 1) { if (x & 1) ret *= tmp; } return ret; } }; const ll MOD = 1e9 + 7; using Mint = modint<MOD>; template <class T> struct Combination { vector<T> fact, factinv; Combination(int n) : fact(n + 1), factinv(n + 1) { fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * T(i); factinv[n] = ~fact[n]; for (int i = n; i >= 1; i--) factinv[i - 1] = factinv[i] * T(i); } T nCr(int n, int r) { if (n < 0 || r < 0 || n < r) return 0; return fact[n] * factinv[r] * factinv[n - r]; } T factorial(int x) { if (x < 0) return 0; return fact[x]; } }; int dp[N][N][N]; int a[N][N]; void done() { int n, k, p; cin >> n >> k >> p; vector<int> a(n); for (int i = 0; i < (n); ++i) { cin >> a[i]; } } void solve() { int n; cin >> n; Mint ans = 1; for (int i = 1; i <= n; ++i) ans *= i; ans -= Mint(2).pow(n - 1); cout << ans << '\n'; } void emer() { int n; cin >> n; vector<int> diamonds, miners; for (int i = 0; i < (2 * n); ++i) { int x, y; cin >> x >> y; if (x == 0) { miners.push_back(abs(y)); } else diamonds.push_back(abs(x)); } sort(miners.begin(), miners.end()); sort(diamonds.begin(), diamonds.end()); long double ans = 0; for (int i = 0; i < (n); ++i) { ans += (long double)sqrt(1ll * miners[i] * miners[i] + 1ll * diamonds[i] * diamonds[i]); } cout << std::fixed << std::setprecision(12) << (ans) << '\n'; } void another() { int n, q; cin >> n >> q; vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; } vector<vector<pair<int, pair<int, int>>>> qur(n); for (int i = 0; i < q; ++i) { int l, r; cin >> l >> r; --l; --r; qur[r].push_back({l, {i, 1}}); if (l) { qur[l - 1].push_back({l, {i, -1}}); } } vector<int> f(n); auto inc = [&](int x) { for (; x < n; x = (x | (x + 1))) f[x]++; }; auto get = [&](int x) { int ans = 0; for (; x >= 0; x = (x & (x + 1)) - 1) ans += f[x]; return ans; }; vector<int> ret(q); map<int, int> last; vector<int> pev(n, -1); for (int i = 0; i < n; ++i) { if (last.count(c[i])) { pev[i] = last[c[i]]; } last[c[i]] = i; inc(pev[i] + 1); for (auto c : qur[i]) { ret[c.second.first] += get(c.first) * c.second.second; } } for (int i = 0; i < (q); ++i) cout << ret[i] << '\n'; } void test_case() { int t; cin >> t; for (int p = 0; p < (t); ++p) { cout << "Case #" << p + 1 << ": "; solve(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; void solve() { long long int n; cin >> n; long long int temp = 1; long long int factorial = 1; for (long long int i = 1; i < (n); i++) { temp *= 2; factorial *= i; temp %= MOD; factorial %= MOD; } factorial *= n; factorial %= MOD; factorial -= temp; if (factorial < 0) factorial += MOD; cout << factorial; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 1e6 + 9; long long fac[N]; long long BigMod(long long a, long long n) { if (n == 0) return 1; long long x = BigMod(a, n / 2); x = (x * x) % mod; if (n & 1) x = (a * x) % mod; return x; } long long ModInv(long long a) { return BigMod(a, mod - 2); } void solve() { long long n; cin >> n; fac[0] = 1; long long ans = 0; for (long long i = 1; i < N; i++) fac[i] = (fac[i - 1] * i) % mod; for (long long i = n / 2; i < n; i++) { ans += ((2 * fac[n - 1]) * ModInv((fac[i] * fac[n - i - 1]) % mod)) % mod; if (n & 1 && i == (n / 2)) ans *= (ModInv(2LL)); ans %= mod; } cout << (fac[n] - ans + mod) % mod << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; long long factn(long long n) { long long f[n + 2]; f[0] = 1; f[1] = 1; for (long long i = 2; i <= n; ++i) { f[i] = (i * f[i - 1]) % 1000000007; } return f[n]; } long long power(long long x, long long y) { long long res = 1; x = x % 1000000007; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res % 1000000007 * x % 1000000007) % 1000000007; y = y >> 1; x = (x % 1000000007 * x % 1000000007) % 1000000007; } return res; } signed main() { long long t = 1; while (t--) { long long n, fact, res; cin >> n; res = 1; fact = 1; for (int i = 1; i <= n - 1; i++) { res *= 2; fact *= i; fact %= 1000000007; res %= 1000000007; } fact *= n; fact %= 1000000007; fact -= res; fact %= 1000000007; if (fact < 0) fact += 1000000007; cout << fact; } }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; void solve() { int n; cin >> n; long long ab = 1; for (long long i = 2; i <= n; i++) ab = (ab * i % mod); long long aa = 1; for (int i = 0; i < n - 1; i++) aa = (2 * aa) % mod; long long ans = ab - aa; if (ans < 0) ans += mod; cout << ans << '\n'; } int main() { cin.tie(0); cout.tie(0); int t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, no = 1, fact = 1; cin >> n; for (int i = 1; i <= n; ++i) fact = (fact * i) % 1000000007; for (int i = 1; i < n; ++i) no = (no * 2) % 1000000007; cout << (fact - no + 1000000007) % 1000000007 << '\n'; }
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; void sol() { long long n; cin >> n; long long ans = 1; long long pre = 0; long long dif = 0; for (int i = 1; i <= n; ++i) { ans = (ans * i) % mod; dif = (pre + 1) % mod; pre = (pre + dif) % mod; } cout << (ans - dif + mod) % mod << "\n"; } int main() { int tc = 1; while (tc--) { sol(); } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long p = 1, ans = 1, n, m = 1e9 + 7; cin >> n; for (int i = 1; i <= n; i++) { ans = (ans * i) % m; } for (int i = 1; i < n; i++) { p = (2 * p) % m; } ans -= p; cout << (ans % m + m) % m; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, f = 1, p = 1, a = 0; cin >> n; for (i = 1; i < n; i++) { f = f * i; f = f % 1000000007; p = p * 2; p = p % 1000000007; } f = f * n; a = a + f; a = a % 1000000007; a = a - p; a = a % 1000000007; if (a < 0) a = a + 1000000007; cout << a << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long n, ans = 1, b = 1; int main() { cin >> n; for (int i = 1; i <= n; i++) ans = ((ans * i) % MOD); for (int i = 1; i < n; i++) b = ((b << 1) % MOD); cout << (ans - b + MOD + MOD) % MOD << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int factorial(long long int n) { if (n == 0) return 1; long long int ans = 1; for (long long int i = 1; i <= n; i++) { ans = ((ans * i) % mod); } return ans; } int main() { long long int n; cin >> n; long long int f1 = factorial(n); f1 = f1 % mod; long long int p = n - 1, f2 = 1; while (p--) { f2 = (f2 * 2) % mod; } f2 = f2 % mod; long long int ans = ((f1 % mod) - (f2 % mod)) % mod; if (ans < 0) ans += mod; cout << ans % mod; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long n, m; string s[105]; long long pw(long long n, long long k) { if (k == 0) return 1; if (k == 1) return n; long long t = pw(n, k / 2); if (k & 1) return t * t % mod * n % mod; else return t * t % mod; } void solve() { long long n, ans = 1; cin >> n; for (int i = 1; i <= n; ++i) ans = (ans * i) % mod; cout << (ans - pw(2, n - 1) + mod) % mod; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if (fopen("codeforces" ".inp", "r")) { freopen( "codeforces" ".inp", "r", stdin); freopen( "codeforces" ".out", "w", stdout); } long long t = 1; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ii = pair<int, int>; ll const mod = ll(1e9) + 7; ll fact[1000050]; ll expo(ll a, ll x) { ll base = a; ll ret = 1; while (x) { if (x & 1) { ret = (ret * base) % mod; } base = (base * base) % mod; x >>= 1; } return ret; } int main() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; fact[0] = 1; for (int i = (1); i < (n + 1); i++) { fact[i] = (fact[i - 1] * i) % mod; } cout << (mod + fact[n] - expo(2, n - 1)) % mod << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 200; const int INF = 1e9; const int MOD = 1e9 + 7; long long ans = 1, power = 1; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i < n; ++i) { ans *= i; power *= 2; ans %= MOD; power %= MOD; } ans = (ans * n) % MOD; ans = (ans - power); while (ans < 0) ans += MOD; cout << ans; return 0; }
#include <bits/stdc++.h> const int MAXNM = 100 + 10; using namespace std; const long long MOD = 1e9 + 7; void process() { int n; cin >> n; long long fact = 1, res = 1; for (int itr = 1; itr < n; itr++) { fact *= itr; res *= 2; fact %= MOD; res %= MOD; } fact *= n; fact %= MOD; fact -= res; if (fact < 0) fact += MOD; fact %= MOD; cout << fact << '\n'; } int main() { process(); return 0; }
#include <bits/stdc++.h> using namespace std; long long factorial(int n) { long long ans = 1; while (n--) { ans = (ans * (n + 1)) % 1000000007; } return ans; } long long power(int n) { long long x = 2; long long res = 1; while (n > 0) { if (n & 1) res = (res * x) % 1000000007; n = n >> 1; x = (x * x) % 1000000007; } return res; } int main() { int t = 1; while (t--) { int n; cin >> n; long long x, y; x = factorial(n); y = power(n - 1); long long ans = (x - y + 1000000007) % 1000000007; cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { int i, j, k, m, n; long long ans, jc = 1, mi = 1; scanf("%d", &n); for (i = 1; i <= n; i++) { jc = jc * i % mod; if (i != 1) mi = (mi * 2) % mod; } printf("%lld\n", ((jc - mi) % mod + mod) % mod); return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; long long int ans = 1; long long int temp = 1; for (int i = 2; i <= n; i++) { ans = (ans * i) % mod; temp = (temp * 2) % mod; } ans = ans - temp; while (ans < 0) { ans += mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> ostream& operator<<(ostream& out, vector<T>& v) { out << "["; for (auto k : v) out << k << " "; out << "]" << "\n"; return out; } template <class T> ostream& operator<<(ostream& out, set<T> s) { out << "{"; for (auto k : s) out << k << " "; out << "}" << "\n"; return out; } template <class T, class U> ostream& operator<<(ostream& out, pair<T, U> p) { out << "[ " << p.first << " , " << p.second << " ] "; return out; } template <class T, class U> istream& operator>>(istream& in, pair<T, U>& p) { in >> p.first >> p.second; return in; } long long mod = 1e9 + 7; long long BinPow(long long b, int e) { if (!e) return 1; if (e & 1) return (b * BinPow(b, e - 1)) % mod; long long bb = BinPow(b, e / 2); return (bb * bb) % mod; } const int maxn = 1e6 + 200; long long fact[maxn], inv[maxn]; long long Comb(int i, int N) { return fact[N] * inv[i] % mod * inv[N - i] % mod; } int main() { cin.tie(0); cin.sync_with_stdio(0); fact[0] = inv[0] = 1; fact[1] = inv[1] = 1; for (int i = int(2); i < int(maxn); i++) { fact[i] = (fact[i - 1] * i) % mod; inv[i] = BinPow(fact[i], mod - 2); } long long res = 0; int N; cin >> N; for (int i = 0; i < int(N); i++) { res += Comb(i, N - 1); if (res >= mod) res -= mod; } long long tres = (fact[N] - res + 10 * mod) % mod; cout << tres << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long n; long long mod = 1000000007; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); while (cin >> n) { long long ret = 1; for (long long i = 1; i <= n; ++i) { ret *= i; ret %= mod; } long long minus = 1; for (int i = 1; i < n; ++i) { minus <<= 1; minus %= mod; } ret += mod; cout << (ret - minus) % mod << endl; } }
#include <bits/stdc++.h> using namespace std; int const N = 1e6 + 1; long long mod = 1e9 + 7; long long fact[N]; long long powmod(long long a, long long b, long long p) { a %= p; if (a == 0) return 0; long long product = 1; while (b > 0) { if (b & 1) { product *= a; product %= p; --b; } a *= a; a %= p; b /= 2; } return product; } long long inv(long long a, long long p) { return powmod(a, p - 2, p); } long long nCk(long long n, long long k, long long p) { return ((fact[n] * inv(fact[k], p) % p) * inv(fact[n - k], p)) % p; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; fact[0] = 1; for (int i = (1); i < (N); ++i) { fact[i] = fact[i - 1] * (long long)i; fact[i] %= mod; } cin >> n; long long ans = fact[n]; for (int i = (0); i < (n); ++i) { ans -= nCk(n - 1, i, mod); ans += mod; ans %= mod; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long binaryExponentiation(long long a, long long b) { long long result = 1; while (b > 0) { if (b % 2 == 1) result = (result * a) % mod; a = (a * a) % mod; b /= 2; } return result % mod; } void solve() { long long n; cin >> n; long long x = n; long long ans = 1; while (x) { ans = (ans * (x)) % mod; x--; } long long d = binaryExponentiation(2, n - 1); if (ans < d) { ans += mod; } ans -= d; ans %= mod; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 100; const int S = 1e6 + 5; const int MOD = 1e9 + 7; long long fac[S] = {0}; long long dp[S] = {0}; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; fac[2] = 2; dp[2] = 0; for (int i = 3; i <= n; i++) { fac[i] = fac[i - 1] * i % MOD; dp[i] = fac[i] - 2 * (fac[i - 1] - dp[i - 1]); dp[i] %= MOD; dp[i] += MOD; dp[i] %= MOD; } cout << dp[n] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long modder = 1e+9 + 7; void solution() { int n; cin >> n; long long out = 1; for (int i = n; i >= 2; i--) { out *= i; out %= modder; } long long lessener = 1; for (int i = 1; i < n; i++) { lessener *= 2; lessener %= modder; } out -= lessener; out %= modder; if (out < 0) { out = modder + out; } cout << out << endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long count, counter = 0; count = 1; while (counter++ < count) { solution(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long Pow(long long n, int k) { if (k == 0) return 1; long long tmp = Pow(n, k / 2) % MOD; tmp = (tmp * tmp) % MOD; if (k % 2) return tmp * n % MOD; else return tmp; } int main() { int n; cin >> n; long long res = 1; for (int i = 1; i <= n; i++) res = (long long)(res * i) % MOD; res = (res - Pow(2, n - 1) + MOD) % MOD; cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; long long ans = 1; long long ans1 = 1; for (int i = 2; i <= n; i++) { ans *= i; ans %= mod; ans1 *= 2; ans1 %= mod; } if (ans < ans1) ans += mod; ans -= ans1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; char a[109][109]; long long fac[1000009]; long long quick_pow(long long x, long long n) { long long ans = 1; while (n) { if (n & 1) ans = ans * x % mod; n >>= 1; x = x * x % mod; } return ans; } long long c(long long n, long long m) { if (m == 0) return 1; return fac[n] * quick_pow(fac[n - m] * fac[m] % mod, mod - 2) % mod; } signed main() { long long n; cin >> n; fac[0] = 1; long long ans = 0; for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod; for (long long i = 1; i <= n; i++) { long long temp = c(n - 1, i - 1) % mod; ans = (ans + temp) % mod; } cout << (fac[n] - ans + mod) % mod; }
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-parameter" using namespace std; const int maxN = 1e6 + 10; const int maxM = 20; const int maxP = 1e4 + 10; const long long INF_LL = 1e17; const int INF = 1e9 + 100; const int MOD = 1e9 + 7; const int Base = 30; const long double EPS = 1e-9; const int BLOCK = 1000; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rnd_64(chrono::steady_clock::now().time_since_epoch().count()); const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; void open_file() {} int power(int a, int n) { int res = 1; for (; n; n >>= 1, a = 1LL * a * a % MOD) { if (n & 1) { res = 1LL * res * a % MOD; } } return res; } int inverse(int a) { return power(a, MOD - 2); } int fact[maxN]; void sol() { int n; cin >> n; fact[0] = 1; for (int i = 1; i <= n; i++) fact[i] = 1LL * fact[i - 1] * i % MOD; cout << (fact[n] - power(2, n - 1) + MOD) % MOD; } void solve() { int T; T = 1; int TestCase = 0; while (T--) { TestCase += 1; sol(); } } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); open_file(); solve(); }
#include <bits/stdc++.h> using namespace std; long long quickmod(long long m, long long n, long long x) { long long k = 1; while (n) { if (n & 1) k = k * m % x; m = m * m % x; n = n / 2; } return k; } int main() { long long n, ans = 1, tmp, i; scanf("%lld", &n); for (i = 1; i <= n; i++) ans = ans * i % 1000000007; tmp = quickmod(2, n - 1, 1000000007); printf("%lld", (ans - tmp + 1000000007) % 1000000007); }
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); signed main() { long long modd = 1e9 + 7; long long n; cin >> n; vector<long long> dp; dp.assign(n + 1, 0); dp[3] = 2; long long fact = 2; for (long long int i = 4; i < n + 1; i++) { fact = ((fact % modd) * ((i - 1) % modd)) % modd; dp[i] = (fact - dp[i - 1]) * (i - 2) + dp[i - 1] * i; dp[i] %= modd; } cout << dp[n] % modd << endl; ; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T& x) { static char c, f; c = getchar(); f = 1, x = 0; for (; !isdigit(c); c = getchar()) if (c == '-') f = -1; for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0'; x *= f; } long long qpow(long long q, long long n, long long mod) { long long ans = 1 % mod; while (n) { if (n & 1) ans = ans * q % mod; q = q * q % mod; n >>= 1; } return ans; } const int inf = 0x3f3f3f3f; const int mod = 7 + 1e9; const int N = 3 + 1e2; int n; int main() { cin >> n; long long ans = 1; for (int i = 1; i <= n; ++i) ans = ans * i % mod; cout << (ans - qpow(2, n - 1, mod) + mod) % mod << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int Mod = (int)1e9 + 7; inline int add(int x, int y) { return ((int)((1ll * ((int)((x) % Mod)) + ((int)((y) % Mod)) + (Mod << 1)) % Mod)); } inline int sub(int x, int y) { return ((int)((1ll * ((int)((x) % Mod)) - ((int)((y) % Mod)) + (Mod << 1)) % Mod)); } inline int mul(int x, int y) { return (int)(( int)((1ll * (((int)((x) % Mod)) + Mod) * (((int)((y) % Mod)) + Mod)) % Mod)); } inline int pow(int x, long long y) { int res = 1; while (y) { if (y & 1ll) res = mul(res, x); x = mul(x, x), y >>= 1ll; } return res; } inline int inv(int x) { return pow(x, 1ll * Mod - 2); } inline int dv(int x, int y) { return mul(x, inv(y)); } const int MAXFAC = (int)2e6 + 10; int fac[MAXFAC]; void init_fac(int maxn) { fac[0] = 1; for (int i = 1; i < maxn; ++i) fac[i] = mul(fac[i - 1], i); } inline int C(int n, int r) { return dv(fac[n], mul(fac[n - r], fac[r])); } void preproc() { init_fac(MAXFAC); } void solve() { int N; cin >> N; cout << sub(fac[N], pow(2, 1ll * N - 1)) << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; preproc(); int tc = 1; for (int Tt = 1; Tt <= tc; ++Tt) { solve(); } return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n; cin >> n; long long tot = 1; long long invalid = 1; for (long long i = 2; i <= n; i++) { tot = tot * i % mod; invalid = invalid * 2 % mod; } cout << (tot - invalid + mod) % mod << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } double distance(int x1, int y1, int x2, int y2) { return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0); } const int mod = 1e9 + 7; int factorial(int n) { return (n == 1 || n == 0) ? 1 : (n + mod) % mod * factorial(n - 1); } bool comp(pair<int, double> a, pair<int, double> b) { if (a.second == b.second) return a.first < b.first; return a.second > b.second; } const int X[] = {1, 0, -1, 0, 1, 1, -1, -1}; const int Y[] = {0, 1, 0, -1, 1, -1, 1, -1}; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t = 1; while (t--) { long long n; cin >> n; long long nas = 0; long long u = 1; for (long long i = 2; i <= n; i++) { u = ((u % mod) * (i % mod)) % mod; u %= mod; } long long h = 1; for (long long i = 1; i <= n - 1; i++) { h = ((h % mod) * (2)) % mod; h %= mod; } nas = u - h; nas = (nas + mod) % mod; cout << nas << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; long long n; int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> n; long long ans = 1, noCicle = 1; for (int i = (2); i <= (n); ++i) { ans *= i; noCicle *= 2; ans %= 1000000007; noCicle %= 1000000007; } ans -= noCicle; if (ans < 0) ans += 1000000007; cout << ans; }
#include <bits/stdc++.h> using namespace std; long long n, f[1000000], m, s, i; long long drunk(long long p) { if (p > 1000000007) return p % 1000000007; else return p; } int main() { cin >> n; f[3] = 2; m = 6; for (i = 4; i <= n; i++) { f[i] = 2 * f[i - 1]; f[i] = drunk(f[i]); s = m * (i - 2); s = drunk(s); f[i] += s; f[i] = drunk(f[i]); m *= i; m = drunk(m); } cout << f[n]; }
#include <bits/stdc++.h> using namespace std; template <typename P, typename Q> P CeilDiv(P _dividend, Q _divider) { return static_cast<P>((_dividend - 1LL + _divider) / _divider); } template <typename Tp> inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") { for (Tp current = _begin; current != _end; ++current) { std::cout << *current << _delim; } std::cout << '\n'; } using ll = long long; using pii = std::pair<int, int>; constexpr int INF = 0x3f3f3f3f; constexpr int MOD = static_cast<const int>(1e9 + 7); int Add(int x, int y) { x += y; return x < MOD ? x : x - MOD; } int Sub(int x, int y) { x -= y; return x >= 0 ? x : x + MOD; } int Mul(int x, int y) { return int(1LL * x * y % MOD); } int FastPow(int x, int p) { int res = 1; while (p > 0) { if (p & 1) { res = Mul(res, x); } p >>= 1; x = Mul(x, x); } return res; } int Inv(int x) { return FastPow(x, MOD - 2); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); int n; cin >> n; int ans = 1; for (int i = 0; i < (n); ++i) { ans = Mul(ans, i + 1); } ans = Sub(ans, FastPow(2, n - 1)); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lli = long long; const lli MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; lli a, b, f; a = 0; f = 1; for (int i = 2; i <= n; ++i) { b = (2 * a + f * (i - 2)) % MOD; a = b; f = f * i % MOD; } cout << b; }
#include <bits/stdc++.h> using namespace std; int read() { int res = 0, f = 0; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') f++, c = getchar(); while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); return f ? -res : res; } const int mod = 1e9 + 7; int main() { int n = read(); int ans1 = 1, ans2 = 1; for (int i = 1; i <= n; i++) { ans1 = 1LL * ans1 * i % mod; if (i < n) ans2 = 1LL * ans2 * 2 % mod; } printf("%d\n", (ans1 - ans2 + mod) % mod); return 0; }
#include <bits/stdc++.h> using namespace std; long long int fact(long long int n) { long long int p = 1; for (long long int i = 1; i < n + 1; i++) p = (p * i) % 1000000007; return p; } void solve() { long long int n, p = 1; cin >> n; long long int x = (fact(n)) % 1000000007; for (long long int i = 1; i < n; i++) { p = p * 2; p = p % 1000000007; } cout << (x - p + 1000000007) % 1000000007 << endl; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int test; test = 1; while (test--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int Nmax = 1e6, MOD = 1e9 + 7; ifstream infile; ofstream outfile; template <class T> void inline Scan(vector<T> &arr) { for (auto &i : arr) cin >> i; } template <class T> void inline Print(vector<T> &arr, char c) { for (auto &i : arr) cout << fixed << setprecision(7) << i << c; } template <class T> istream &operator>>(istream &in, pair<T, T> &p) { in >> p.first >> p.second; return in; } template <class T> ostream &operator<<(ostream &out, pair<T, T> &p) { out << p.first << ' ' << p.second; return out; } template <class T> void swap(pair<T, T> &p) { swap(p.first, p.second); } template <class T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } long long power(long long x, int y) { long long ans = 1; while (y) { if (y % 2 == 1) ans = (ans * x) % MOD; x = (x * x) % MOD; y = y / 2; } return ans; } template <class T> T solve() { long long n, ans = 1; cin >> n; for (auto i = 2; i != n + 1; i++) ans = (ans * i) % MOD; ans = (ans - power(2, n - 1) + MOD) % MOD; cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; vector<int> ans(T); for (auto t = 0; t != T; t++) { solve<void>(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long p, ans; long long modinv(long long num, long long md) { p = md - 2; ans = 1; for (; p; num = (num * num) % md, p /= 2) { if (p & 1) ans = (ans * num) % md; } return ans; } const long long N = 1e6 + 1; long long f[N]; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n, tot, i, num, temp, den; cin >> n; f[0] = 1; for (i = 1; i <= n; ++i) { f[i] = (f[i - 1] * i) % 1000000007; } tot = 2; for (i = 2; i < n; ++i) { num = f[n - 1]; den = (f[n - 1 - (i - 1)] * f[i - 1]) % 1000000007; den = modinv(den, 1000000007); temp = (num * den) % 1000000007; tot = (tot + temp) % 1000000007; } long long ans; ans = (f[n] - tot) % 1000000007; ans = (ans + 1000000007) % 1000000007; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long md = 1e9 + 7; long long fact[1000007]; void pre() { fact[0] = 1; for (long long i = 1; i <= 1000002; i++) fact[i] = (fact[i - 1] * i) % md; } long long mul(long long a, long long b) { return (a * b) % md; } long long power(long long a, long long n) { if (n == 0) return 1; long long ans = power(a, n / 2); if (n % 2) return mul(ans, mul(ans, a)); return mul(ans, ans); } long long inv(long long x) { return power(x, md - 2); } long long c(long long n, long long r) { return mul(fact[n], inv(mul(fact[r], fact[n - r]))); } int32_t main() { c_p_c(); long long n; cin >> n; pre(); long long ans = fact[n] - 2; for (long long i = 1; i <= n - 2; i++) ans -= c(n - 1, i); ans = (ans) % md; ans = (ans + md) % md; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long llinf = 10000000000000ll; int gcd(int a, int b) { if (b == 0) return a; a %= b; return gcd(b, a); } void setIO(string name) { freopen(("./contests/663/" + name + ".in").c_str(), "r", stdin); freopen(("./contests/663/" + name + ".out").c_str(), "w", stdout); } const int MX = 1000005, M = 1e9 + 7; int t, n; vector<long long> dp(MX, -1); void solve() { cin >> n; long long res = 1, fact = 1; for (int i = (1); i < (n); ++i) { res *= 2; fact *= i; res %= M; fact %= M; } fact *= n; fact %= M; long long ans = fact - res; ans %= M; if (ans < 0) ans += M; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); t = 1; for (int i = (0); i < (t); ++i) { solve(); } }
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { long long int res = 1; x = x % 1000000007; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % 1000000007; y = y >> 1; x = (x * x) % 1000000007; } return res; } long long int modFact(long long int n) { if (n >= 1000000007) return 0; long long int result = 1; for (long long int i = 1; i <= n; i++) result = (result * i) % 1000000007; return result; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { long long int n; cin >> n; long long int ans = modFact(n); ans = (ans - power(2, n - 1) + 1000000007) % 1000000007; cout << ans << "\n"; } return 0; }