CF226C.Anniversary

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 AA , consisting of numbers ll , l+1l+1 , l+2l+2 , ...... , rr ; let's consider all its kk -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=1F_{1}=1 , F2=1F_{2}=1 , Fn=Fn1+Fn2F_{n}=F_{n-1}+F_{n-2} for n>=3n>=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 mm .

输入格式

The first line contains four space-separated integers mm , ll , rr and kk (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.

输出格式

Print a single integer — the residue from dividing the sought greatest common divisor by mm .

输入输出样例

  • 输入#1

    10 1 8 2
    

    输出#1

    3
    
  • 输入#2

    10 1 8 3
    

    输出#2

    1
    
首页