#K39437. Filter Numbers Divisible by 3
Filter Numbers Divisible by 3
Filter Numbers Divisible by 3
You are given a list of integers. Your task is to filter out all numbers that are divisible by 3. If a number is divisible by 3, it should be included in the output list; otherwise, it should be ignored.
In mathematical terms, a number num is divisible by 3 if and only if \( num \mod 3 = 0 \).
The input starts with an integer n
which indicates the number of elements in the sequence. The next line contains n
space-separated integers. You need to output the numbers that satisfy the divisibility condition in the same order as they appear in the input. If no numbers are divisible by 3, output an empty line.
inputFormat
The input is given via standard input as follows:
n num1 num2 ... numn
Where n
is an integer representing the number of elements, and the next line contains exactly n
space-separated integers.
outputFormat
Output the list of numbers divisible by 3 in a single line, separated by a single space. If no number is divisible by 3, print an empty line.
## sample6
1 3 5 9 12 15
3 9 12 15
</p>