Problem3047--巨大的斐波那契数[Colossal Fibonacci Numbers,UVa11582]

3047: 巨大的斐波那契数[Colossal Fibonacci Numbers,UVa11582]

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Status] [Submit] [Creator:]

Description

 第i个斐波那契数f(i)定义如下:
 f(0)=0 and f(1)=1
 f(i+2) = f(i+1)+f(i) (i≥0)
 给定两个非负整数a、b和正整数n,请计算出除以n的余数

Input

 第一行,一个整数t,表示测试数据的组数(t≤10000)
 接下来t行,每行3个整数分别表示a、b、n(0≤a,b<2^64;1≤n≤1000)

Output

 每组测试数据输出一行,表示除以n的余数

Sample Input Copy

3
1 1 2
2 3 1000
18446744073709551615 18446744073709551615 1000

Sample Output Copy

1
21
250

Source/Category