Maximum sum
Practice
0 (0 votes)
Hiring
Open
Hiring
Open
Hiring
Math
Implementation
Math basic
Basic math
Mathematics
Easy
Basic programming
Problem
48% Success 97 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a positive integer \(N\). Your task is to determine the maximum value of \(X\), where for any value of \(K\) between \(1\) to \(N\), the value of \(X\) is as follows:
\( X = \sum\limits_{i=1}^K ((-1)^{i+1})(i)(i+1) \) .
Input format
- First line: \(T\) denoting the number of test cases
- Next \(T\) lines: A single integer \(N\)
Output format
For each test case, print the maximum value of \(X\).
Constraints
\( 1 \le T \le 10^{5} \)
\( 1 \le N \le 10^{9} \)
\( 1 \le K \le N \)
Sample Input
2 3 5
Sample Output
8 18
Explanation
for First Testcase , ( 1 * 2 - 2 * 3 + 3 * 4) = 12 is the maximum possible value for X.
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
AlgorithmsQuick SortSorting
Points:20
19 votes
Tags:
ApprovedDepth First SearchEasyGraphsReady
Points:20
200 votes
Tags:
ApprovedBinary SearchEasyOpenSorting
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor