跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2690. Anniversary

  • ID: 2696
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:挑战
  • 上传者:
  • 数据结构
  • 模拟
  • 数学
  • 矩阵运算
  • 数论
  • 编程与模拟
  • 挑战
  • 难度
  • 共享题库
  • Codeforces
  • 英文题面
  • 题目来源
  • 题面语言

Anniversary

题目描述

C. Anniversary
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 F1=1, F2=1, Fn=Fn-1+Fn-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≤109;1≤l<r≤1012;2≤k≤r-l+1).

Please, do not use the %lld specifier to read or write 64-bit integers in C++. 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.

Examples
Input
10 1 8 2
Output
3
Input
10 1 8 3
Output
1

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2355 题。保留原作者与原赛事署名。