#C7175. Cookie Packaging Problem
Cookie Packaging Problem
Cookie Packaging Problem
You are given an integer \( n \) representing the exact number of cookies to be packaged. There are two types of packaging available:
- A single-cookie package.
- A box that holds exactly 3 cookies.
Your task is to determine the minimal combination of packages such that the total number of cookies is exactly \( n \). In other words, find two non-negative integers \( p_1 \) and \( p_2 \) where \( p_1 \) is the number of single packages and \( p_2 \) is the number of 3-cookie boxes, satisfying:
[ p_1 + 3p_2 = n ]
The strategy is straightforward: use as many 3-cookie boxes as possible, and package the remainder with single-cookie packages. Note that some cases might allow two possible answers, but any valid one will be accepted.
Examples:
- For \( n = 15 \), a valid answer is \( p_1 = 0, p_2 = 5 \) since \( 0 + 3 \times 5 = 15 \).
- For \( n = 7 \), a valid answer is \( p_1 = 1, p_2 = 2 \) since \( 1 + 3 \times 2 = 7 \).
- For \( n = 1 \), a valid answer is \( p_1 = 1, p_2 = 0 \).
- For \( n = 10 \), a valid answer is \( p_1 = 1, p_2 = 3 \) since \( 1 + 3 \times 3 = 10 \).
- For \( n = 1000000000 \), one possible answer is \( p_1 = 1, p_2 = 333333333 \).
- For \( n = 5 \), a valid answer is \( p_1 = 2, p_2 = 1 \) since \( 2 + 3 \times 1 = 5 \).
inputFormat
The first line contains an integer \( T \) representing the number of test cases. Each of the next \( T \) lines contains a single integer \( n \), the number of cookies in the order.
Input is read from stdin.
outputFormat
For each test case, output two integers \( p_1 \) and \( p_2 \) separated by a space, where \( p_1 \) is the number of single packages and \( p_2 \) is the number of 3-cookie boxes needed. Each answer should be printed on a new line to stdout.
## sample6
15
7
1
10
1000000000
5
0 5
1 2
1 0
1 3
1 333333333
2 1
</p>