AvtoBus (Codeforces 1679A)
Tags: Greedy, number theory

Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses.You own a small bus service business and you have just received an order to replace $$$n$$$ tires. You know that the bus fleet owns two types of buses: with two axles (these buses have $$$4$$$ wheels) and with three axles (these buses have $$$6$$$ wheels).You don't know how many buses of which type the AvtoBus bus fleet owns, so you wonder how many buses the fleet might have. You have to determine the minimum and the maximum number of buses that can be in the fleet if you know that the total number of wheels for all buses is $$$n$$$.

Input: The first line contains an integer $$$t$$$ ($$$1 \le t \le 1\,000$$$) — the number of test cases. The following lines contain description of test cases.The only line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^{18}$$$) — the total number of wheels for all buses.

Output: For each test case print the answer in a single line using the following format.Print two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \le y$$$) — the minimum and the maximum possible number of buses that can be in the bus fleet.If there is no suitable number of buses for the given $$$n$$$, print the number $$$-1$$$ as the answer.

Note: In the first test case the total number of wheels is $$$4$$$. It means that there is the only one bus with two axles in the bus fleet.In the second test case it's easy to show that there is no suitable number of buses with $$$7$$$ wheels in total.In the third test case the total number of wheels is $$$24$$$. The following options are possible:  Four buses with three axles.  Three buses with two axles and two buses with three axles.  Six buses with two axles. So the minimum number of buses is $$$4$$$ and the maximum number of buses is $$$6$$$.

Sample Inputs:
4
4
7
24
998244353998244352

Sample Outputs:
1 1
-1
4 6
166374058999707392 249561088499561088

Solution (Python):
h = int(input())
for i in range(h):
    a = int(input())
    if a % 2 == 1 or a < 4:
        print(-1)
    else:
        if a % 12 == 0:
            m1 = a // 6
            m2 = a // 4
        elif a % 4 == 0:
            m1 = a // 6 + 1
            m2 = a // 4
        elif a % 6 == 0:
            m1 = a // 6
            m2 = a // 4
        else:
            m1 = a // 6 + 1
            m2 = a // 4
        print(min(m1, m2), max(m1, m2))

Solution (Python):
t = int(input())
for i in range(t):
    n = int(input())
    if n % 2 != 0 or n < 4:
        print(-1)
    else:
        print((n + 4) // 6, n // 4)

Solution (Python):
from sys import stdin

def ii():
    return int(stdin.readline())

def mi():
    return map(int, stdin.readline().split())

def li():
    return list(mi())

def si():
    return stdin.readline()
t = 1
t = ii()
for _ in range(t):
    n = ii()
    if n < 4 or n & 1:
        print(-1)
        continue
    print((n + 5) // 6, n // 4)