#include <bits/stdc++.h>
using namespace std;
long long md;
long long a[5000000];
void mul(long long a[2][2], long long b[2][2], long long c[2][2]) {
  long long d[2][2];
  int i, j, k;
  memset(d, 0, sizeof(d));
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 2; k++) {
        d[i][j] += (a[i][k] * b[k][j]) % md;
        d[i][j] %= md;
      }
    }
  }
  for (i = 0; i < 2; i++)
    for (j = 0; j < 2; j++) c[i][j] = d[i][j];
  return;
}
int fib(long long x) {
  long long top, d[200], m1[2][2], m[2][2];
  int i;
  top = -1;
  while (x > 0) {
    top++;
    d[top] = x % 2;
    x = x / 2;
  }
  m1[0][0] = 1;
  m1[0][1] = 1;
  m1[1][0] = 1;
  m1[1][1] = 0;
  m[0][0] = 1;
  m[0][1] = 0;
  m[1][0] = 0;
  m[1][1] = 1;
  for (i = top; i >= 0; i--) {
    mul(m, m, m);
    if (d[i] == 1) mul(m, m1, m);
  }
  return m[1][0];
}
int main() {
  long long l, r, kk;
  long long i, j, k, s;
  cin >> md >> l >> r >> kk;
  i = 1;
  while (i * i <= r) {
    a[i - 1] = i;
    i++;
  }
  k = i;
  for (j = 1; j <= i; j++) {
    a[k - 1] = r / j;
    k++;
  }
  k--;
  sort(a, a + k);
  for (i = k - 1; i >= 0; i--) {
    s = r / a[i] - (l - 1) / a[i];
    if (s >= kk) {
      break;
    }
  }
  cout << fib(a[i]) << endl;
  return 0;
}
