Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器 软件资源

软件开发小程序制作系统集成与运维空间租用硬件开发视频监控技术咨询与支持——联系电话:0311-88999002/88999003

首页 / 软件开发 / 数据结构与算法 / 10299 Problem A: Modular Fibonacci(斐波那契的矩阵快速幂)

10299 Problem A: Modular Fibonacci(斐波那契的矩阵快速幂)2014-04-20 csdn博客 accelerator_Problem A: Modular Fibonacci

The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...) are defined by the recurrence:

F0 = 0

F1 = 1

Fi = Fi-1 + Fi-2 for i>1

Write a program which calculates Mn = Fn mod 2m for given pair of n and m. 0 n 2147483647 and 0 m< 20. Note that a mod b gives the remainder when a is divided by b.

Input and Output

Input consists of several lines specifying a pair of n and m. Output should be corresponding Mn, one per line.

Sample Input

11 7

11 6

Sample Output

89

25