#include <bits/stdc++.h>
inline long long read() {
  register long long x = 0;
  register int y = 1;
  register char c = std::getchar();
  while (c < '0' || c > '9') {
    if (c == '-') y = 0;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return y ? x : -x;
}
long long mod, l, r, k;
struct matrix {
  long long a[2][2];
};
inline matrix mul(const matrix &a, const matrix &b) {
  matrix c;
  std::memset(c.a, 0, sizeof c.a);
  for (register int i = 0; i < 2; i++)
    for (register int j = 0; j < 2; j++) {
      for (register int k = 0; k < 2; k++)
        c.a[i][j] += a.a[i][k] * b.a[k][j] % mod, c.a[i][j] %= mod;
    }
  return c;
}
inline matrix power(matrix a, long long b) {
  matrix ans;
  ans.a[0][0] = ans.a[1][1] = 1;
  ans.a[0][1] = ans.a[1][0] = 0;
  while (b) {
    if (b & 1) ans = mul(ans, a);
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}
inline long long F(long long i) {
  if (i == 1 || i == 2) return 1 % mod;
  matrix a;
  a.a[0][0] = a.a[0][1] = a.a[1][0] = 1;
  a.a[1][1] = 0;
  a = power(a, i - 2);
  return (a.a[0][0] + a.a[1][0]) % mod;
}
inline int check(long long i) { return r / i - (l - 1) / i >= k; }
int main() {
  mod = read();
  l = read();
  r = read();
  k = read();
  long long ans = 0;
  for (register long long i = 1, nex; i <= r; i = nex + 1) {
    nex = r / (r / i);
    if (check(nex)) ans = std::max(ans, nex);
  }
  printf("%lld\n", F(ans));
  return 0;
}
