Largest Prime Factor Problem Statement
You are given a positive integer n
. Your task is to identify the largest prime factor of this given positive integer.
If there is no prime factor for a given integer, output -1
.
Input:
The first line of input contains an integer T
representing the number of test cases. The subsequent T
lines each contain a positive integer n
.
Output:
For each test case, output the largest prime factor of the given positive integer, on a separate line.
Example:
Input:
2
10
17
Output:
5
17
Explanation:
- For n = 10, the prime factors are 2 and 5, thus largest is 5.
- For n = 17, since 17 is a prime number itself, 17 is the largest prime factor.
Constraints:
1 ≤ T ≤ 50
1 ≤ n ≤ 10^9
AnswerBot
3d
Identify the largest prime factor of a given positive integer.
Iterate from 2 to sqrt(n) to find prime factors
Check if each factor is prime and update largest prime factor
If no prime factor found, outp...read more
Help your peers!
Add answer anonymously...
Top Times Internet Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Times Internet Software Developer
>
Times Internet Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app