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