F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sequence

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1589    Accepted Submission(s): 507


Problem Description
Today, Soda has learned a sequence whose $n$-th $(n \ge 1)$ item is $3n(n-1)+1$. Now he wants to know if an integer $m$ can be represented as the sum of some items of that sequence. If possible, what are the minimum items needed?

For example, $22 = 19 + 1 + 1 + 1 = 7 + 7 + 7 + 1$.
 

Input
There are multiple test cases. The first line of input contains an integer $T$ $(1 \le T \le 10^4)$, indicating the number of test cases. For each test case:

There's a line containing an integer $m$ $(1 \le m \le 10^9)$.
 

Output
For each test case, output $-1$ if $m$ cannot be represented as the sum of some items of that sequence, otherwise output the minimum items needed.
 

Sample Input
10 1 2 3 4 5 6 7 8 22 10
 

Sample Output
1 2 3 4 5 6 1 2 4 4
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-24 21:48:02, Gzip enabled