If you want to find the most innovative students at RHHS, there's only one place to look: TEJ4M1. Here, the students are always finding new ways to challenge reality and solve unknown problems. On an average day in TEJ4M1, the students had an extra-special idea. They decided to stack all of the AA batteries in the classroom into triangles of different base sizes, as shown below.
However, they encountered a little problem. Out of the
In order to help them, you, as the Gordon of the class, need to find the number of batteries required to create the maximum number of pyramids.
Input Specification
The first line will contain
The next
For test cases worth 20 of 100 points,
For test cases worth an additional 30 points,
Output Specification
Output a single integer, representing the number of batteries required to create the maximum number of pyramids with the given number of available batteries.
Sample Input 1
1
40 10
Sample Output 1
20
Explanation for Sample 1
Of the
Sample Input 2
1
10000 1000
Sample Output 2
8436
Explanation for Sample 2
Use the first 36 triangles. 1 + 3 + 6 + 10 + 15 + 21 + 28 + 36 + 45 + 55 + 66 + 78 + 91 + 105 + 120 + 136 + 153 + 171 + 190 + 210 + 231 + 253 + 276 + 300 + 325 + 351 + 378 + 406 + 435 + 465 + 496 + 528 + 561 + 595 + 630 + 666 = 8436
Comments