Harshit wants to save money for his first car. He puts money in the Ninja bank every day.
He starts by putting in ‘1’ rupee on Monday, the first day. Every day from Tuesday to Sunday, he will put in ‘1’ rupee more than the day before. On every subsequent Monday, he will put in ‘1’ rupee more than the previous Monday.
You are given ‘N’, your task is to return the total amount of money he will have in the Ninja bank at the end of the ‘N’th day.
For example:
Given ‘N’ = 2
On Day 1 = 1
On Day 2 = 2
Total Amount = 1 + 2 = 3.
Therefore the answer is 3.
Input format :
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and the only line of each test case contains a single integer ‘N’,that is the number of days.
Output format :
For each test case, print the total amount of money after N days.
The output of each test case will be printed in a separate line.
Constraints:
1 <= T <= 10
1 <= N <= 5000
Where ‘T’ is the total number of test cases, and N is the number of days.
Time limit: 1sec.
2
2
7
3
28
For first test case :
On Day 1 = 1
On Day 2 = 2
Total Amount = 1 + 2 = 3.
Therefore the answer is 3.
For Second Test case:
On Day 1 = 1
On Day 2 = 2
On Day 3 = 3
On Day 4 = 4
On Day 5 = 5
On Day 6 = 6
On Day 7 = 7
Total Amount = 1 + 2 + 3 + 4 + 5 + 6 + 7= 28.
Therefore the answer is 28.
2
8
9
30
33
Can we bruteforce?
The main idea is to loop from 1 to ‘N’ and add 1 coin more than we did yesterday and every time we complete a week, set the coin value to the number of weeks that have passed.
O(N), where N is the number of days.
Since we are looping from 1 to N therefore net complexity is O(N).
O(1).
Since we are not using any extra space.