CRDS - Cards

no tags 

Maricruz have a lot of cards, she always uses her cards to build pyramids as shown in the following image:

Cards

A pyramid card of 3 levels. She always wonder how many cards does she need to make a pyramid card of N levels. Your task is to answer that question.

Input

The first line of the input contains an integer 1 <= T <= 1,000. Each of the following T lines will have an integer 1 <= N <= 1,000,000.

Output

For each case, output a single line consisting of the number of cards needed to build a pyramid card of level N modulo 1,000,007.

Example

Input Example
2
3
7

Output Example
15
77

hide comments
tiksna: 2020-01-11 20:32:59

It's just simple math. Try finding an equation by analyzing the pattern

hellb0y_suru: 2019-12-20 16:45:54

at i'th level, there are 'i' triangles , each triangle takes 3 cards (except the last level's triangle which takes only 2 cards)
so the total answer will be = (3*1 + 3*2 + 3*3 + 3+4 ...... 3*n) - (n)
which is equal to , 3*(1+2+3+4+5 ...... + n) - n ;
::: dont forget to use long long instead of int, dont forget to use modulo

lx_lovin: 2019-12-06 13:53:07

Use Memoization

dartes: 2019-12-02 01:52:13

Why should we use long long for n? The range is 1 <= n <= 1000000. Costed me few WA's

trhgquan: 2019-11-04 16:28:01

using DP, AC in 1 node.

darker__space: 2019-10-02 15:54:00

make sure you take modulo(% ) at the final answer ...applying modulo meanwhile ...in wrong way may change ur answer and give wrong answer :<

codequant: 2019-09-24 09:59:50

Piece of cake! Just find the pattern in the image given. NOTE: Don't forget the last Modulo part of the problem.

s_h_i_1: 2019-07-27 08:25:54

general formula is very easy to derive... think level wise ... after that use modulo property [ (a*b)%c =( (a%c)*(b%c))%c ]

aryan29: 2019-05-31 23:16:47

Easy one

py_tyagi: 2019-05-11 07:45:54

doing it level%(1000000007) but it is(1000007)


Added by:Paulo Costa
Date:2012-01-30
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:UGTO