#include <bits/stdc++.h>
using namespace std;
const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
long long m, l, r, k;
vector<vector<long long> > mul(vector<vector<long long> > &A,
                               vector<vector<long long> > &B) {
  vector<vector<long long> > C(A.size(), vector<long long>(B[0].size()));
  for (int i = 0; i < A.size(); ++i) {
    for (int k = 0; k < B.size(); ++k) {
      for (int j = 0; j < B[0].size(); ++j) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % m;
      }
    }
  }
  return C;
}
vector<vector<long long> > pow(vector<vector<long long> > A, long long n) {
  vector<vector<long long> > B(A.size(), vector<long long>(A.size()));
  for (int i = 0; i < A.size(); ++i) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
bool chk(long long x) { return r / x - (l - 1) / x >= k; }
int main() {
  cin >> m >> l >> r >> k;
  vector<vector<long long> > A(2, vector<long long>(2));
  A[0][0] = A[1][0] = A[0][1] = 1;
  A[1][1] = 0;
  long long idx = 0;
  for (long long i = 1; i * i <= r; i++) {
    if (chk(i)) {
      idx = max(idx, i);
    }
    if (chk(r / i)) {
      idx = max(idx, r / i);
    }
  }
  A = pow(A, idx);
  cout << (A[1][0] % m) << endl;
}
