Codeforces Round 140 (Div. 2)
E
Anniversary
Codeforces
未评级
原题
← D→
翻译中…

There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations.

翻译中…

Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set $*A*$, consisting of numbers $*l*$, $*l* + 1$, $*l* + 2$, $...$, $*r*$; let's consider all its $*k*$-element subsets; for each such subset let's find the largest common divisor of Fibonacci numbers with indexes, determined by the subset elements. Among all found common divisors, Dima is interested in the largest one.

翻译中…

Dima asked to remind you that Fibonacci numbers are elements of a numeric sequence, where $*F*_{1} = 1$, $*F*_{2} = 1$, $*F*_{*n*} = *F*_{*n* - 1} + *F*_{*n* - 2}$ for $*n* ≥ 3$.

翻译中…

Dima has more than half a century ahead to solve the given task, but you only have two hours. Count the residue from dividing the sought largest common divisor by $*m*$.

翻译中…

Input

翻译中…

The first line contains four space-separated integers $*m*$, $*l*$, $*r*$ and $*k*$ $(1 ≤ *m* ≤ 10^{9}; 1 ≤ *l* < *r* ≤ 10^{12}; 2 ≤ *k* ≤ *r* - *l* + 1)$.

翻译中…

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

翻译中…

Output

翻译中…

Print a single integer — the residue from dividing the sought greatest common divisor by $*m*$.

翻译中…

样例

Input #1
10 1 8 2
Output #1
3
InputCopy OutputCopy
Input #2
10 1 8 3
Output #2
1
InputCopy OutputCopy
题目信息
题号
227E
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。