Boredom buster (Easy)
InterviewTime limit1sMemory limit1024 MB
Given n, split each integer by fixed rules and find the maximum total of y*z over all splits until n ones remain.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Recursion
- Solved
- No attempts yet
Problem
Gillian is normally a very lively child. Most of the time she plays with her friends and tries to indulge in some mischief. But today is different. Today Gillian woke up with the flu, so she has to stay in bed, still and bored. To entertain her, her brother came up with the following game.
When Gillian has an integer greater than 1, she can split it into two positive integers and such that . After performing this operation, her brother gives her hazelnuts. However, not all pairs of are valid. There are some rules Gillian must comply with. These rules differ between the easy and hard subproblems, and they are listed in the problem specification section.
Numbers obtained from this operation can also be split. At the beginning of the game, Gillian starts with a single integer . She performs a series of operations described above until she is left with copies of the number 1. What is the maximum number of hazelnuts she can win if she chooses her moves wisely?
For any there is exactly one valid way of splitting:
- if is divisible by 3, then and ;
- if is divisible by 2 (but not by 3), then ;
- otherwise, and .
Input
The first line of the input contains an integer specifying the number of test cases. Each test case is preceded by a blank line.
Each test case contains a single line with Gillian's initial integer . You may assume that .
Output
For each test case, output a single line with the maximum number of hazelnuts.