#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int M = 1e6 + 10;
int n, dp[M][21][2];
int f(int x, int y) { return n / ((y ? 3 : 1) << x); }
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  int p = log2(n);
  dp[1][p][0] = 1;
  if ((1 << (p - 1)) * 3 <= n) dp[1][p - 1][1] = 1;
  for (int i = 1; i <= n - 1; i++)
    for (int x = 0; x <= 20; x++)
      for (int y = 0; y <= 1; y++) {
        dp[i + 1][x][y] =
            (dp[i + 1][x][y] + 1LL * dp[i][x][y] * (f(x, y) - i) % mod) % mod;
        if (x)
          dp[i + 1][x - 1][y] =
              (dp[i + 1][x - 1][y] +
               1LL * dp[i][x][y] * (f(x - 1, y) - f(x, y)) % mod) %
              mod;
        if (y)
          dp[i + 1][x][y - 1] =
              (dp[i + 1][x][y - 1] +
               1LL * dp[i][x][y] * (f(x, y - 1) - f(x, y)) % mod) %
              mod;
      }
  printf("%d\n", dp[n][0][0]);
  return 0;
}
