#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 2e5 + 5;
const long long limit1 = 1e6 + 5;
const long long limit2 = 1e3 + 5;
pair<int, int> dir[] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                        {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
pair<int, int> NON = {-1, -1};
int n;
int f[limit1][21][2];
int cal(int j, int k) { return n / ((1 << j) * (k ? 3 : 1)); }
void solveProblem() {
  long long lim = 0;
  while ((1LL << lim) <= n) ++lim;
  --lim;
  f[0][lim][0] = 1;
  if (lim && 3LL * (1LL << (lim - 1)) <= n) f[0][lim - 1][1] = 1;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j <= (19); ++j) {
      for (int k = (0); k <= (1); ++k) {
        f[i + 1][j][k] += (f[i][j][k] * 1LL * (cal(j, k) - i - 1)) % MOD,
            f[i + 1][j][k] %= MOD;
        if (j)
          f[i + 1][j - 1][k] +=
              (f[i][j][k] * 1LL * (cal(j - 1, k) - cal(j, k))) % MOD,
              f[i + 1][j - 1][k] %= MOD;
        if (k)
          f[i + 1][j][k - 1] +=
              (f[i][j][k] * 1LL * (cal(j, k - 1) - cal(j, k))) % MOD,
              f[i + 1][j][k - 1] %= MOD;
      }
    }
  }
  int ans = 0;
  for (int j = (0); j <= (19); ++j) {
    for (int k = (0); k <= (1); ++k) {
      ans += f[n - 1][j][k], ans %= MOD;
    }
  }
  cout << ans << '\n';
}
void fastInput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void readInput() { cin >> n; }
int main() {
  fastInput();
  readInput();
  solveProblem();
}
