#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, x, y, f[1000010][20][2];
inline int w(int x, int y) { return (1 << x) % mod * (y ? 3 : 1) % mod; }
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ '0');
    c = getchar();
  }
  return x * f;
}
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 = w(j, k);
        f[i][j][k] +=
            1ll * f[i - 1][j][k] * (n / now % mod - (i - 1) % mod) % mod;
        f[i][j][k] %= mod;
        if (j) {
          f[i][j - 1][k] += 1ll * f[i - 1][j][k] *
                            (n / w(j - 1, k) % mod - n / now % mod) % mod;
          f[i][j - 1][k] %= mod;
        }
        if (k) {
          f[i][j][k - 1] += 1ll * f[i - 1][j][k] *
                            (n / w(j, k - 1) % mod - n / now % mod) % mod;
          f[i][j][k - 1] %= mod;
        }
      }
  printf("%d", f[n][0][0]);
  return 0;
}
