#K67902. Largest Prime Factor Array
Largest Prime Factor Array
Largest Prime Factor Array
You are given a list of n integers. For each integer ni, your task is to compute its largest prime factor. For the purpose of this problem, if ni ≤ 1, consider its largest prime factor as 1.
The largest prime factor of a positive integer n is defined as the largest prime number that divides n. Mathematically, for n > 1, if we factorize it as \[ n = p_1^{a_1} \times p_2^{a_2} \times \cdots \times p_k^{a_k}, \] then the largest prime factor is pk (assuming p1 < p2 < ... < pk). If n ≤ 1, output should be 1.
The function should process the list in a single pass and output the results in the same order.
inputFormat
The input is read from stdin and follows the format below:
T n1 n2 ... nT
Where:
T
is an integer representing the number of test cases (or elements in the list).- The next line contains
T
space-separated integers.
outputFormat
Output a single line to stdout containing T
numbers. Each number is the largest prime factor corresponding to the input integer at that position. Separate the outputs by a single space.
5
10 15 21 29 49
5 5 7 29 7