#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
inline int read() {
  int res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) res = (res << 1) + (res << 3) + c - 48, c = getchar();
  return res * f;
}
int f[maxn][20][2];
int n, x, y;
inline int gets(int x, int y) { return (1 << x) % mod * (y ? 3 : 1) % mod; }
int main() {
  n = read();
  x = log2(n);
  f[1][x][0] = 1;
  if ((1 << (x - 1)) * 3 <= n) {
    f[1][x - 1][1] = 1;
    y = 1;
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= x; j++) {
      for (int k = 0; k <= y; k++) {
        int now = gets(j, k);
        f[i][j][k] =
            (1ll * f[i][j][k] +
             1ll * f[i - 1][j][k] * (n / now % mod - (i - 1) % mod) % mod) %
            mod;
        if (j)
          f[i][j - 1][k] =
              1ll *
              (1ll * f[i][j - 1][k] +
               1ll * f[i - 1][j][k] * (n / gets(j - 1, k) - n / now) % mod) %
              mod;
        if (k)
          f[i][j][k - 1] =
              1ll *
              (1ll * f[i][j][k - 1] +
               1ll * f[i - 1][j][k] * (n / gets(j, k - 1) - n / now) % mod) %
              mod;
      }
    }
  }
  printf("%d\n", f[n][0][0]);
  return 0;
}
