Triangular Test II

Hugov Molotov, an evil computer scientist, is obsessed by triangular numbers and how to use them to control the world. Molotov wants to choose a new henchman, so he has prepared a hard task, to test if you are worthy. The task consist in, given a positive integer number N, tell what is the minimum amount of triangular numbers whose sum is equal to N. Note: a triangular number is given by: ∑X i=1+2+3+4+···+X i=1 where X is any positive integer number. Input The input may contain several test cases. Each test case is presented on a single line, and contains one positive integer N (1 ≤ N ≤ 107). The end of the test cases is given by the end of file (EOF). Output For each test case, your program must print one positive integer denoting the minimum amount of triangular numbers, whose sum is equal to N. Each test case must generate one output line. Sample Input 1 2 6 10 Sample Output 1 2 1 1