#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int dp[1000005][25][2];
signed main() {
  int n;
  scanf("%d", &n);
  int num2 = log2(n);
  dp[1][num2][0] = 1;
  if ((1 << (num2 - 1)) * 3 <= n) dp[1][num2 - 1][1] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; (1 << j) <= n; j++) {
      dp[i][j][0] =
          (long long)((long long)dp[i - 1][j + 1][0] *
                          ((n / (1 << j)) - (n / (1 << (j + 1)))) % mod +
                      (long long)dp[i - 1][j][1] *
                          (n / ((1 << j)) - (n / ((1 << j) * 3))) +
                      (long long)dp[i - 1][j][0] * ((n / (1 << j)) - i + 1) %
                          mod) %
          mod;
      dp[i][j][1] =
          (long long)((long long)dp[i - 1][j + 1][1] *
                          ((n / ((1 << j) * 3)) - (n / ((1 << (j + 1)) * 3))) %
                          mod +
                      (long long)dp[i - 1][j][1] *
                          (n / ((1 << j) * 3) - i + 1) % mod) %
          mod;
    }
  }
  printf("%d", dp[n][0][0]);
  return 0;
}
