#include <bits/stdc++.h>
const int mod = 1000000007, maxn = 1000005, maxl = 25;
int n, max2;
int f[maxn][maxl][2];
inline void add(int a, int b, int c, int x, int y, int z, int k) {
  f[a][b][c] = (f[a][b][c] + 1ll * f[x][y][z] * k % mod) % mod;
}
int main() {
  scanf("%d", &n);
  for (max2 = 1; (1 << (max2 + 1)) <= n; max2++)
    ;
  f[1][max2][0] = 1;
  if ((1 << (max2 - 1)) * 3 <= n) f[1][max2 - 1][1] = 1;
  for (int i = 2; i <= n; i++)
    for (int j = 0; j <= max2; j++) {
      int k = 1 << j;
      add(i, j, 0, i - 1, j, 0, (n / k) - (i - 1));
      if (j < max2) add(i, j, 0, i - 1, j + 1, 0, n / k - n / (k * 2));
      add(i, j, 0, i - 1, j, 1, n / k - n / (k * 3));
      add(i, j, 1, i - 1, j, 1, n / (k * 3) - (i - 1));
      if (j < max2) add(i, j, 1, i - 1, j + 1, 1, n / (k * 3) - n / (k * 6));
    }
  printf("%d\n", f[n][0][0]);
  return 0;
}
