#include <bits/stdc++.h>
using namespace std;
int main() {
  const int64_t mod = 1000000007;
  auto sub = [&](int64_t a, int64_t b) { return a < b ? a - b + mod : a - b; };
  auto add = [&](int64_t a, int64_t b) { return sub(a, mod - b); };
  auto mul = [&](int64_t a, int64_t b) { return a * b % mod; };
  int n, k = 0;
  cin >> n;
  for (int m = n >> 1; m; m >>= 1) ++k;
  if (n & 1 << (k - 1)) {
    cerr << "if" << endl;
    vector<int> num(k + k + 1), cnt(k + k + 1);
    vector<vector<int>> son(k + k + 1);
    for (int i = 0; i <= k; ++i) {
      num.at(i + i) = 1 << i;
      if (i != k) {
        num.at(i + i + 1) = (1 << i) * 3;
        son.at(i + i).emplace_back(i + i + 1);
        son.at(i + i).emplace_back(i + i + 2);
      }
      if (i < k - 1) son.at(i + i + 1).emplace_back(i + i + 3);
    }
    for (int i = 0; i <= k + k; ++i) cnt.at(i) = n / num.at(i);
    vector<int64_t> dp0(k + k + 1), dp1(k + k + 1);
    dp0.at(k + k) = 1;
    dp0.at(k + k - 1) = 1;
    for (int i = 1; i != n; ++i) {
      fill(dp1.begin(), dp1.end(), 0);
      for (int j = 0; j <= k + k; ++j)
        if (i < cnt.at(j)) {
          dp1.at(j) = mul(dp0.at(j), cnt.at(j) - i);
          for (const auto& s : son.at(j))
            dp1.at(j) = add(dp1.at(j), mul(dp0.at(s), cnt.at(j) - cnt.at(s)));
        }
      swap(dp0, dp1);
    }
    cout << dp0.front() << endl;
  } else {
    vector<int> num(k + 1), cnt(k + 1);
    vector<vector<int>> son(k + 1);
    for (int i = 0; i <= k; ++i) {
      num.at(i) = 1 << i;
      if (i != k) son.at(i).emplace_back(i + 1);
      cnt.at(i) = n / num.at(i);
    }
    vector<int64_t> dp0(k + 1), dp1(k + 1);
    dp0.back() = 1;
    for (int i = 1; i != n; ++i) {
      fill(dp1.begin(), dp1.end(), 0);
      for (int j = 0; j <= k; ++j)
        if (i < cnt.at(j)) {
          dp1.at(j) = mul(dp0.at(j), cnt.at(j) - i);
          for (const auto& s : son.at(j))
            dp1.at(j) = add(dp1.at(j), mul(dp0.at(s), cnt.at(j) - cnt.at(s)));
        }
      swap(dp0, dp1);
    }
    cout << dp0.front() << endl;
  }
}
