OHANISER - Ohani And The Series

no tags 

Now a days, Ohani has become very expert in mathematics. Her teachers like her very much because of her excellent performance. 

One day, one of her teacher gave her a problem to solve. He will give Ohani a number N. This will represent a table of N rows. The first row contains number from 1 to N. Then the next line will contain N-1 numbers, In the second row, the first number will be the summation of the first two numbers (1 + 2) of the previous row, the second number will be the summation of the second two numbers (2 + 3) of the previous row and so on. Row 3 will have N-2 numbers with same procedures. Same procedure follows for row 4, row 5, .... , row N. On the last row, there will be only a single number. Ohani has to tell that only number of the Nth row.

For example: If N = 4, then the table is:

1   2   3   4

 3    5    7

    8   12


So Ohani has to answer the last remaining number: 20.

She can answer when N is small, but can't when N is large. Can you help her?


The first line contains the number of testcases T (T <= 100000).

Each of the test cases contain a number N where 1 <= N <= 100000.


You have to output the case number and the required answer. As the number can be very large, output the answer modulo 1000000007.


2 Output: Case 1: 1
Case 2: 3

hide comments
rishabh_1997: 2016-07-07 06:48:48

Learnt modular exponentiation... Also good precomputation of formula

vineetpratik: 2016-07-04 14:40:58

make a formula->get tle->use modular exp->ac

KD : 2016-05-25 12:10:09

AC in one go :P

samanway1996: 2016-05-09 18:34:32

Only precomputation is enough... no modular exponentiation is needed :-P

Anant Upadhyay: 2015-08-03 10:31:43

Use modular exponentiation

Dhruv k14: 2015-03-05 20:36:46

Not typing "Case n: " cost me 5 WAs aaaaaaargghhh

Roy Rohit: 2015-02-10 19:19:06

what is the answer for 100000???

Last edit: 2015-02-10 19:19:27
Raj Kumar Chauhan: 2015-02-01 16:04:04

TLE, WA, Overflow again and again :(
TLE is default result for this problem :p
Finally AC :) :), ques taught many things :)

Last edit: 2015-02-02 06:46:23
pk: 2015-02-01 09:51:29

my 100 on spoj :)

Aman: 2015-02-01 08:48:40

My 50th one .... :)

Added by:Raihat Zaman Neloy
Time limit:0.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64