#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tos(T a) {
  stringstream ss;
  string ret;
  ss << a;
  ss >> ret;
  return ret;
}
void read(int &_a) { int temp = scanf("%d", &_a); }
void read(int &_a, int &_b) { int temp = scanf("%d %d", &_a, &_b); }
void read(int &_a, int &_b, int &_c) {
  int temp = scanf("%d %d %d", &_a, &_b, &_c);
}
const int SZ = 1e6 + 7;
const long long MOD = 1e9 + 7;
int memo[SZ][22][2];
int N;
long long cmult(long long x, long long y) {
  long long d = 1ll << x;
  if (y) d *= 3ll;
  return N / d;
}
int main() {
  while (cin >> N) {
    int X = 0;
    while (1 << X <= N) X++;
    X--;
    memset(memo, 0, sizeof memo);
    ;
    memo[1][X][0] = 1;
    if (((1 << X) / 2) * 3 <= N) memo[1][X - 1][1] = 1;
    for (int(pos) = (1); (pos) < (N); (pos)++) {
      for (int(x) = (0); (x) < (X + 1); (x)++)
        for (int(y) = (0); (y) < (2); (y)++) {
          long long v = (memo[pos][x][y] * (cmult(x, y) - pos)) % MOD;
          memo[pos + 1][x][y] = (memo[pos + 1][x][y] + v) % MOD;
          if (x) {
            v = (memo[pos][x][y] * (cmult(x - 1, y) - cmult(x, y))) % MOD;
            memo[pos + 1][x - 1][y] = (memo[pos + 1][x - 1][y] + v) % MOD;
          }
          if (y) {
            v = (memo[pos][x][y] * (cmult(x, y - 1) - cmult(x, y))) % MOD;
            memo[pos + 1][x][y - 1] = (memo[pos + 1][x][y - 1] + v) % MOD;
          }
        }
    }
    cout << memo[N][0][0] << endl;
  }
  return 0;
}
