Smallest prime factor

Write codeMedium15 min

Your task

Return the smallest prime factor of a positive integer n (with n up to about 10^12). If n is prime, the smallest prime factor is n itself. Return -1 for n < 2. Handle the factor 2 first, then trial-divide by odd numbers up to sqrt(n); the first odd divisor found is the smallest prime factor.

Examples

smallest_prime_factor(n: int) -> int
Example 1
Inputsmallest_prime_factor(21)
Output3