#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, N = 1e6 + 5;
int dp[N][21][2], n, v;
const int v1(int i, bool j) { return (1 << i) * (j ? 3 : 1); }
const int tj(int i, int j) { return n / v1(i, j); }
int main() {
  scanf("%d", &n);
  v = log2(n);
  dp[1][v][0] = 1;
  dp[1][v - 1][1] = v1(v - 1, 1) <= n;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j <= v; j++) {
      dp[i][j][0] = (1ll * dp[i - 1][j][0] * (tj(j, 0) - i + 1) +
                     1ll * dp[i - 1][j + 1][0] * (tj(j, 0) - tj(j + 1, 0)) +
                     1ll * dp[i - 1][j][1] * (tj(j, 0) - tj(j, 1))) %
                    M;
      dp[i][j][1] = (1ll * dp[i - 1][j][1] * (tj(j, 1) - i + 1) +
                     1ll * dp[i - 1][j + 1][1] * (tj(j, 1) - tj(j + 1, 1))) %
                    M;
    }
  }
  printf("%d", dp[n][0][0]);
  return 0;
}
