CSU 1402: Fibonacci Multiply

题目:

Description

In mathematics, the Fibonacci number are the number in the following integer sequence:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34….

The nth Fibonacci number Fn, is defined by the recurrence relation

Fn = F- 1 + F- 2

with F0 = 0, F1 = 1.

Given two positive integers xy, calculate (Fx * Fy) % 1000000007.

Input

The first line contains the number of test cases T (1 <= T <= 50).

For each test case, there is only one line with two integers xy (1 <= xy <= 106).

Output

For each test case, output (Fx * Fy) % 1000000007.

扫描二维码关注公众号,回复: 469706 查看本文章

Sample Input

3
3 4
7 1
8 8

Sample Output

6
13
441

代码:

#include<iostream>
using namespace std;

int f[1000001];

int main()
{
	f[0] = 0, f[1] = 1;
	for (int i = 2; i <= 1000000; i++)f[i] = (f[i - 1] + f[i - 2]) % 1000000007;
	int t, x, y;
	cin >> t;
	while (t--)
	{
		cin >> x >> y;
		long long r = f[x];
		cout << r*f[y] % 1000000007 << endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/nameofcsdn/article/details/80235768