#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const int mod = 1e9 + 7;
long long dp[2][24][2], base2[24], base3[2];
int n;
int main() {
  scanf("%d", &n);
  int x = n, k = 0, w = 0;
  while (x != 1) {
    k++;
    x >>= 1;
  }
  if ((1 << (k - 1)) * 3 <= n) w++;
  if (w) dp[1][k - 1][w] = 1;
  dp[1][k][0] = 1;
  base2[0] = base3[0] = 1;
  base3[1] = 3;
  for (int i = 2; i <= n; ++i) {
    for (int j = 0; j <= k; ++j) {
      dp[i & 1][j][0] = 0;
      if (j < k)
        dp[i & 1][j][0] =
            (dp[i & 1][j][0] + dp[(i - 1) & 1][j + 1][0] *
                                   ((n / ((1 << j))) - (n / ((1 << (j + 1))))) %
                                   mod) %
            mod;
      dp[i & 1][j][0] = (dp[i & 1][j][0] +
                         dp[(i - 1) & 1][j][1] *
                             ((n / ((1 << j))) - (n / ((1 << j) * 3))) % mod) %
                        mod;
      dp[i & 1][j][0] = (dp[i & 1][j][0] + dp[(i - 1) & 1][j][0] *
                                               (n / ((1 << j)) - i + 1) % mod) %
                        mod;
      dp[i & 1][j][1] = 0;
      if (j < k)
        dp[i & 1][j][1] =
            (dp[i & 1][j][1] +
             dp[(i - 1) & 1][j + 1][1] *
                 ((n / ((1 << j) * 3)) - (n / ((1 << (j + 1)) * 3))) % mod) %
            mod;
      dp[i & 1][j][1] =
          (dp[i & 1][j][1] +
           dp[(i - 1) & 1][j][1] * (n / ((1 << j) * 3) - i + 1) % mod) %
          mod;
    }
  }
  printf("%lld", dp[n & 1][0][0]);
  return 0;
}
