#include <bits/stdc++.h>
using namespace std;
namespace Fread {
const int MAXN = 1 << 20;
char buf[MAXN], *S, *T;
inline char getchar() {
  if (S == T) {
    T = (S = buf) + fread(buf, 1, MAXN, stdin);
    if (S == T) return EOF;
  }
  return *S++;
}
}  // namespace Fread
inline int read() {
  int x(0), neg(1);
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') neg = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch - '0');
    ch = getchar();
  }
  return x * neg;
}
const int MAXN = 1e6;
const int mod = 1e9 + 7;
int n, x, y;
int cnt;
int ok;
int dp[MAXN + 5][21][2];
signed main() {
  x = 1ll;
  n = read();
  while (true) {
    if (x > n) {
      x /= 2;
      --cnt;
      break;
    }
    x = x * 2;
    ++cnt;
  }
  if (x / 2 * 3 <= n) ok = 1, y = x / 2 * 3;
  dp[1][cnt][0] = 1;
  dp[1][cnt - 1][1] = ok;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j <= cnt; ++j) {
      dp[i][j][0] = (1ll * dp[i - 1][j][0] * (n / (1 << (j)) - (i - 1))) % mod;
      dp[i][j][0] =
          (dp[i][j][0] + 1ll * dp[i - 1][j + 1][0] *
                             (n / (1 << j) - n / (1 << (j + 1))) % mod) %
          mod;
      if (!ok) continue;
      dp[i][j][0] =
          (dp[i][j][0] +
           1ll * dp[i - 1][j][1] * (n / (1 << j) - n / ((1 << j) * 3)) % mod) %
          mod;
      dp[i][j][1] =
          (1ll * dp[i - 1][j][1] * (n / ((1 << j) * 3) - (i - 1))) % mod;
      dp[i][j][1] =
          (dp[i][j][1] + 1ll * dp[i - 1][j + 1][1] *
                             (n / ((1 << j) * 3) - n / ((1 << (j + 1)) * 3)) %
                             mod) %
          mod;
    }
  }
  printf("%d\n", dp[n][0][0]);
  return 0;
}
