CF226C.Anniversary

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

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 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.

距离著名意大利数学家斐波那契(Leonardo Fibonacci)900周年诞辰纪念日还剩不到60年。当然,如此重要的纪念日需要大量准备工作。

迪马(Dima)坚信:在“大日子”来临之前,掌握如下问题的解法将非常有意义:给定一个集合 AA,它由整数 l,l+1,l+2,…,rl, l+1, l+2, \dots, r 构成;考虑 AA 的所有 kk 元子集;对每个这样的子集,计算其元素作为下标所对应的斐波那契数的最大公约数(GCD)。在所有求得的这些最大公约数中,迪马关心的是其中最大的那个值。

迪马提醒你:斐波那契数列是一个数列,满足 F1=1F_1 = 1,F2=1F_2 = 1,且对所有 n≥3n \geq 3,有 Fn=Fn−1+Fn−2F_n = F_{n-1} + F_{n-2}。

迪马还有半个多世纪的时间来解决该问题,而你仅有两小时。请计算所求的最大公约数对 mm 取模所得的余数。

输入格式

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 С++. It is preferred to use cin, cout streams or the %I64d specifier.

第一行包含四个以空格分隔的整数 mm、ll、rr 和 kk(1 ≤ m ≤ 1091 ≤ m ≤ 10^9;1 ≤ l < r ≤ 10121 ≤ l < r ≤ 10^{12};2 ≤ k ≤ r − l + 12 ≤ k ≤ r - l + 1)。

请注意,在 C++ 中读取或写入 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流,或 %I64d 说明符。

输出格式

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

输出一个整数——即所求最大公约数对 mm 取模后的余数。

输入输出样例

  • 输入#1

    10 1 8 2

    输出#1

    3
  • 输入#2

    10 1 8 3

    输出#2

    1

输入解题思路,AI测评打分。不知道怎么写?

首页