Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (tutorial)

10724. Sum of Tetranacci numbers (easy)

Problem code: TETRASUM

The sequence of Tetranacci numbers is defined as follows:
an = an-1 + an-2 + an-3 + an-4 with a0 = a1 = a2 = 0 and a3 = 1.

Input

Input starts with a positive integer t ≤ 4000, then t lines follow. Each of the t lines contains two space separated integers m and n with 0 ≤ m ≤ n ≤ 109.

Output

Calculate am + am+1 + ... + an and print the result modulo 1000000007.

 

Example

Input:
2
1 2
1919 5393

Output:
0
66616

Note: If your solution is fast enough, you may try the classical version.


Added by:numerix
Date:2012-02-18
Time limit:30s
Source limit:10000B
Languages:All
Resource:own problem

hide comments
2012-03-13 15:03:41 numerix
I increased the number of testcases and the time limit and moved the problem to tutorial section. All former AC solutions passed. Similar problems are SEQ and SPP.
I added a harder version in the classical section (same testcases, stricter time limit).

Last edit: 2012-02-26 12:40:58
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.