#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n;
long long mod = 1e9 + 7;
int dp[N][22][2];
int cnt(int x) { return n / x; }
int main() {
  scanf("%d", &n);
  int up = log2(n);
  dp[1][up][0] = 1;
  if ((1 << up) / 2 * 3 <= n) dp[1][up - 1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= up; j++) {
      dp[i][j][0] =
          (dp[i][j][0] +
           dp[i - 1][j + 1][0] *
               (1ll * (cnt((1 << j)) - cnt(1 << (j + 1))) % mod) % mod +
           dp[i - 1][j][0] * (1ll * (cnt(1 << j) - i + 1) % mod) % mod % mod +
           dp[i - 1][j][1] *
               (1ll * (cnt((1 << j)) - cnt((1 << j) * 3)) % mod)) %
          mod;
      dp[i][j][1] =
          ((dp[i][j][1] + dp[i - 1][j][1] *
                              (1ll * (cnt(((1 << j)) * 3) - i + 1) % mod) %
                              mod) +
           dp[i - 1][j + 1][1] *
               (1ll * (cnt(((1 << j) * 3)) - 1ll * cnt(((1 << (j + 1)) * 3))) %
                mod) %
               mod) %
          mod;
    }
  }
  printf("%d", dp[n][0][0]);
}
