#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int f[1000010][30][2], n;
int main() {
  scanf("%d", &n);
  int lg = 0;
  for (int i = 1; i <= n; i <<= 1) lg++;
  lg--;
  f[1][lg][0] = 1;
  if ((1 << (lg - 1)) * 3 <= n) f[1][lg - 1][1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 0; j <= lg; j++) {
      f[i][j][0] =
          (1ll * f[i - 1][j][0] * (n / (1 << j) - i + 1) +
           1ll * f[i - 1][j + 1][0] * (n / (1 << j) - n / (1 << (j + 1))) +
           1ll * f[i - 1][j][1] * (n / (1 << j) - n / ((1 << j) * 3))) %
          mod;
      f[i][j][1] = (1ll * f[i - 1][j][1] * (n / ((1 << j) * 3) - i + 1) +
                    1ll * f[i - 1][j + 1][1] *
                        (n / ((1 << j) * 3) - n / ((1 << (j + 1)) * 3))) %
                   mod;
    }
  printf("%d\n", f[n][0][0]);
}
