#include <bits/stdc++.h>
using namespace std;
int power(int a, int b, int m, int ans = 1) {
  for (; b; b >>= 1, a = 1LL * a * a % m)
    if (b & 1) ans = 1LL * ans * a % m;
  return ans;
}
int ct[1000010];
int r;
int f[1000010];
int g[1000010];
int C(int n, int m) {
  if (m > n) return 0;
  int vv = 1LL * g[n - m] * g[m] % 1000000007;
  vv = 1LL * vv * f[n] % 1000000007;
  return vv;
}
int calc() {
  int ans = 1;
  for (int i = 0; i <= r; i++) ans = 1LL * ans * f[ct[i]] % 1000000007;
  int cnt = ct[0];
  for (int i = 1; i <= r; i++) {
    int add = C(cnt + ct[i], ct[i]) - C(cnt + ct[i] - 1, ct[i]);
    if (add >= 1000000007) add -= 1000000007;
    if (add < 0) add += 1000000007;
    ans = 1LL * ans * add % 1000000007;
    cnt += ct[i];
  }
  return ans;
}
int main() {
  f[0] = 1;
  for (int i = 1; i < 1000010; i++) f[i] = 1LL * f[i - 1] * i % 1000000007;
  g[1000010 - 1] = power(f[1000010 - 1], 1000000007 - 2, 1000000007);
  for (int i = 1000010 - 2; i >= 0; i--)
    g[i] = 1LL * g[i + 1] * (i + 1) % 1000000007;
  int n;
  scanf("%d", &n);
  int st = 1;
  r = 0;
  while (st <= n) {
    r++;
    st *= 2;
  }
  r--;
  st = 1;
  ct[r] = 1;
  for (int i = 0; i < r; i++) {
    ct[i] = n / st - (n / (st * 2));
    st *= 2;
  }
  int ans = 0;
  ans += calc();
  if (ans >= 1000000007) ans -= 1000000007;
  int v = 3 * (1 << (r - 1));
  if (v <= n) {
    for (int i = 1; i <= r; i++) {
      ct[r] = 1;
      int val = v;
      for (int j = 1; j <= r; j++) {
        int f;
        if (j == i)
          f = 3;
        else
          f = 2;
        val /= f;
        ct[r - j] = (n / val) - (n / (val * f));
      }
      ans += calc();
      if (ans >= 1000000007) ans -= 1000000007;
    }
  }
  printf("%d\n", ans);
  return 0;
}
