fork download
  1. # your code goes here
  2. def get_smallest_prime_factor(n):
  3. if n <= 1:
  4. return None # 0 and 1 don't have prime factors
  5.  
  6. # Check every number from 2 up to sqrt(n)
  7. i = 2
  8. while i * i <= n:
  9. if n % i == 0:
  10. return i # First divisor found is the smallest prime factor
  11. i += 1
  12.  
  13. return n # If no divisor found, n itself is prime
  14.  
  15. # Example Usage:
  16. num = 35
  17. print(f"Smallest prime factor of {num} is {get_smallest_prime_factor(num)}")
  18. # Output: 5
  19.  
Success #stdin #stdout 0.07s 14032KB
stdin
Standard input is empty
stdout
Smallest prime factor of 35 is 5