当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3978:Evil teacher's Final Problem

题目描述
In the math class, the evil teacher gave you one unprecedented problem!

Here f(n) is the n-th fibonacci number (n >= 0)! Where f(0) = f(1) = 1 and for any n > 1, f(n) = f(n - 1) + f(n - 2). For example, f(2) = 2, f(3) = 3, f(4) = 5 ...

The teacher used to let you calculate f(n) mod p where n <= 10^18 and p <= 10^9, however , as an ACMER, you may just kill it in seconds! The evil teacher is mad about this. As you kill the Evil teacher.s problem in second too!!! now he let you calculate G(n,k) .Here G(n,0) = f(n) , G(n,i) = f( G(n,i-1) ) (k >= i >= 1). However the G(n,k) may be so large ,so you just need to output the remainder of the answer after divided by p.

Note: This problem is the evil teacher's final problem, it is really hard ! If you could solve this problem during the competition, you will be reward in the ACM_DIY gathering.
输入解释
The first line is one integer T indicates the number of the test cases. (T <=500000)

Then for every case, three integers n k and p . (0 <= n <= 10^9,0 <= k <= 10^4, 1 <= p <= 10^8)
输出解释
Output one line.

First output “Case #idx: ”, here idx is the case number count from 1.Then output remainder of the answer after divided by p.
输入样例
10 
1 10000 100000000 
2 3 10000 
3 97 98 
4 2 10 
5 1 29 
1234 5678 100000000 
3344 5566 77889900 
10000 10000 100000000 
1111 10000 90000000 
999 876 10000000
输出样例
Case #1: 1 
Case #2: 2 
Case #3: 3 
Case #4: 4 
Case #5: 5 
Case #6: 17835789 
Case #7: 5381861 
Case #8: 71647609 
Case #9: 43710337
Case #10: 9102595
来自杭电HDUOJ的附加信息
Author AekdyCoin
Recommend

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-3978

最后修改于 2020-10-25T23:08:56+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
45000/15000MS(Java/Others) 32768/32768K(Java/Others)