#B3711. Transform to Multiple of 4
Transform to Multiple of 4
Transform to Multiple of 4
You are given a positive integer n. In one operation, you may choose a contiguous segment of digits (when the number is considered as a string) and remove these digits. Formally, if s is the digit string of n with length L, an operation is defined by two indices 0 ≤ i ≤ j ≤ L-1 and the resulting number will be formed by concatenating s[0:i]
and s[j+1:L]
. Note that you are not allowed to remove all digits (the resulting number must be non-empty). Also, doing nothing is allowed, and it counts as at most one operation.
Your task is: For a given positive integer n, determine whether it is possible, by performing at most one operation (or no operation at all), to transform n into a number that is a multiple of 4.
Note: An integer is divisible by 4 if and only if:
- It is a single-digit number that is either 4 or 8, or
- If it has at least two digits, the number formed by its last two digits (in latex: $\textbf{last two digits}$) is divisible by 4.
For example, consider n = 123456. If we choose to remove the digits corresponding to the 2nd to 3rd digits from the end (i.e. digits '5' and '4'), the remaining number becomes 1236, which is a multiple of 4 since 36 is divisible by 4.
inputFormat
The first line contains an integer T — the number of test cases.
Each of the following T lines contains a positive integer n.
Input Format (latex):
T
n1
n2
...
nT
outputFormat
For each test case, output a single line containing YES if it is possible to transform n into a multiple of 4 using at most one operation, and NO otherwise.
Output Format (latex):
YES/NO for each test case in a separate line
sample
3
124
123
101
YES
YES
NO
</p>