#include <bits/stdc++.h>
__attribute__((always_inline, optimize(3))) __inline__ void add(int *x, int y) {
  (*x += y) >= 1000000007 && (*x -= 1000000007);
}
__attribute__((always_inline, optimize(3))) __inline__ int mul(int x, int y) {
  return (long long)x * y - (long long)x * y / 1000000007 * 1000000007;
}
__attribute__((always_inline, optimize(3))) __inline__ int f(int n, int x,
                                                             int y) {
  int tmp = 1 << x;
  y && (tmp *= 3);
  return n / tmp;
}
int main() {
  int n, p = 0;
  scanf("%d", &n);
  static int dp[1000005][21][2] = {};
  while ((1 << p) <= n) ++p;
  dp[1][--p][0] = 1;
  if ((3 << p - 1) <= n) dp[1][p - 1][1] = 1;
  for (int i = 1; i < n; ++i)
    for (int x = 0; x <= p; ++x)
      for (int y = 0; y < 2; ++y) {
        add(dp[i + 1][x] + y, mul(dp[i][x][y], f(n, x, y) - i));
        x && (add(dp[i + 1][x - 1] + y,
                  mul(dp[i][x][y], f(n, x - 1, y) - f(n, x, y))),
              0);
        y && (add(dp[i + 1][x] + y - 1,
                  mul(dp[i][x][y], f(n, x, y - 1) - f(n, x, y))),
              0);
      }
  printf("%d\n", dp[n][0][0]);
  return 0;
}
