Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Largest Prime Factor

Find the largest prime that divides a positive integer.

A prime is an integer greater than 1 with no positive divisors other than 1 and itself. Find the largest prime factor of n. When n is itself prime, return n.

Implement largest_prime_factor(n).

Input

n: The integer to factor.

Output

Return its largest prime divisor.

Ràng buộc

2 ≤ n ≤ 10¹². The input 1 is excluded because it has no prime factor.

Ví dụ

Ví dụ 1
Đầu vào:
n = 84

Kết quả mong đợi:
expected = 7
Đầu vào:
long long n = 84;

Kết quả mong đợi:
long long expected = 7;
Đầu vào:
long n = 84;

Kết quả mong đợi:
long expected = 7;

Giải thích

84 = 2 × 2 × 3 × 7, so the largest prime factor is 7.

Ví dụ 2
Đầu vào:
n = 13

Kết quả mong đợi:
expected = 13
Đầu vào:
long long n = 13;

Kết quả mong đợi:
long long expected = 13;
Đầu vào:
long n = 13;

Kết quả mong đợi:
long expected = 13;

Giải thích

13 is prime, so it is its own largest prime factor.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.