Hyper Hexagonality X17088


Statement
 

pdf   zip

html

An old Measharan proverb says that a good day must include a reference to hexagons. Ronald Zynoulus has received his prize from Gill Bytes, in a huge amount of coins. Thus, he has started to arrange them in hexagonal patterns on his game board. He called a number N hexagonal iff there is a regular hexagon on a hex grid which contains exactly N hexes. Thus, the first four hexagonal numbers are: 1, 7, 19, 37.

                                       * * * *
                          * * *       * * * * *
                 * *     * * * *     * * * * * *
            *   * * *   * * * * *   * * * * * * *
                 * *     * * * *     * * * * * *
                          * * *       * * * * *
                                       * * * *

Ronald wants to use all of his K coins to build such hexagons. Each non-negative integer can be written as a sum of hexagonal numbers, for example, 27 = 19 + 7 + 1. Of course, he would like to use as few hexagons as possible. He called the smallest number of hexagonal components of K the hyperhexagonality of K.

Your task is to calculate the hyperhexagonality of the given number.

Input

Input consists of T cases (T ≤ 100). Each case is a single number K, 1 ≤ K ≤ 1012. The input ends with 0.

Output

For each K in the input, output its hyperhexagonality.

Public test cases
  • Input

    1
    6
    7
    19
    27
    0
    

    Output

    1
    6
    1
    1
    3
    
  • Information
    Author
    Eryk Kopczynski
    Language
    English
    Official solutions
    Unknown. This problem is being checked.
    User solutions
    C++