Last Updated: 26 Sep, 2025

Vehicle Fleet Combinations

Easy
Asked in company
Amazon

Problem statement

You are given an integer W representing a total number of wheels. You have an infinite supply of two-wheeled and four-wheeled vehicles.

Your task is to find the number of different ways to choose a fleet of vehicles such that the total number of wheels is exactly W. Two ways are considered different if they use a different number of two-wheeled vehicles or a different number of four-wheeled vehicles.

You will be given T independent queries, each with a different value for W.


Input Format:
The first line of input contains an integer T, the number of test cases (queries).

The next T lines each contain a single integer W, the total number of wheels for that query.


Output Format:
For each query, print a single integer on a new line representing the number of valid vehicle combinations.


Note:
The problem can be modeled by the equation 2*x + 4*y = W, where x is the number of two-wheelers and y is the number of four-wheelers.

Since 2x and 4y are both even, their sum W must also be even. If W is an odd number or less than 2, no solution is possible (except for W=0, which has one solution: zero vehicles).

For a valid (non-negative, even) W, the equation can be simplified by dividing by 2: x + 2*y = W/2.

Rearranging gives x = W/2 - 2*y. Since x must be non-negative (x >= 0), we have W/2 - 2*y >= 0, which means y <= W/4.

Therefore, the number of possible values for y (the number of 4-wheelers) ranges from 0 to floor(W/4). The number of ways is simply floor(W/4) + 1.