#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
const int mod = 1e9 + 7;
int dp[N][21][2];
int n, f[21][2], two[21], three[2];
long long a, b, c;
signed main() {
  scanf("%d", &n);
  for (int i = 0; i <= 20; ++i) {
    if (n < (int)(pow(2, i))) break;
    for (int j = 0; j <= 1; ++j) {
      if (n < (int)(pow(2, i) * pow(3, j))) break;
      f[i][j] = n / (int)(pow(2, i) * pow(3, j));
    }
  }
  three[0] = two[0] = 1;
  three[1] = 3;
  for (int i = 1; i <= 20; ++i) {
    two[i] = two[i - 1] * 2;
  }
  memset(dp, 0, sizeof(dp));
  a = log2(n);
  dp[1][a][0] = 1;
  if (n >= pow(2, a - 1) * 3) dp[1][a - 1][1] = 1;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j <= 20; ++j) {
      if (n < two[j]) break;
      for (int k = 0; k <= 1; ++k) {
        if (n < two[j] * three[k]) break;
        b = dp[i - 1][j][k];
        c = f[j][k] - (i - 1);
        a = (b * c) % mod;
        a %= mod;
        if (n >= two[j + 1] * three[k]) {
          b = dp[i - 1][j + 1][k];
          c = f[j][k] - f[j + 1][k];
          a += (b * c) % mod;
          a %= mod;
        }
        if (!k && n >= two[j] * three[k + 1]) {
          b = dp[i - 1][j][k + 1];
          c = f[j][k] - f[j][k + 1];
          a += (b * c) % mod;
          a %= mod;
        }
        dp[i][j][k] = a % mod;
      }
    }
  }
  printf("%d", dp[n][0][0]);
}
