TRICOUNT - Counting Triangles
We define the LEVEL of a triangle as in the following illustrative image:
Task: Your task is very easy. All you have to do is to count all triangles in the biggest one (Level N).
Input
The first line of the input contains an integer T (T ≤ 10000) - the number of test cases and T lines follow. Each line contains an integer N (1 ≤ N ≤ 106) which is the level of the triangle in that test case.
Output
For each test case, you should write a seperate line: the number of triangles in the biggest one (Level N). (All answers will fit within the range of a 64-bit integer)
Example
Input:
3
1
2
3
Output:
1
5
13
Source limit is 500 bytes.
hide comments
savage_19:
2020-02-05 08:17:35
Use long data type.. costed many WAs. |
|
rushout09:
2019-09-12 17:38:58
This video will help you understand the concept:
|
|
quannguyenlhp:
2019-08-12 11:02:59
Don't use the formula, try to come up with another solution less than 500b, it's more challenge. Last edit: 2019-08-12 11:03:26 |
|
hetp111:
2019-05-24 21:59:35
For those who think 4th level should be 3rd level... here we are adding 2n-1 triangles to the base of n-1th level to find the nth level, so nth_lvl=(n-1)th_lvl + (2n-1)smalltrianglesOnBase Last edit: 2019-05-24 22:02:33 |
|
klmo:
2019-04-26 16:31:12
Whats the deal with the source code size limit!!! |
|
knir0103:
2019-03-20 08:54:34
can calculate upwards and downwards separately, not necessarily using formula :) |
|
rahul11197:
2019-03-19 12:49:39
ans=ceil ( (n*(n+2)*(2*n+1) ) / 2 ) |
|
vaibhav18_:
2019-01-01 16:30:53
easy one if u know the formula
|
|
knakul853:
2018-11-01 11:13:34
just find formula : ) |
|
masterchef2209:
2018-10-18 14:52:35
costed too many WAs :( |
Added by: | nha.duong |
Date: | 2007-08-05 |
Time limit: | 1s |
Source limit: | 500B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 ERL JS-RHINO NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | Trần Huy Hưng |