fork download
  1. def is_prime(n):
  2. """Check if a number is a prime number."""
  3. if n <= 1:
  4. return False
  5. if n <= 3:
  6. return True
  7. if n % 2 == 0 or n % 3 == 0:
  8. return False
  9. i = 5
  10. while i * i <= n:
  11. if n % i == 0 or n % (i + 2) == 0:
  12. return False
  13. i += 6
  14. return True
  15.  
  16. def sum_of_primes_below(limit):
  17. """Calculate the sum of all prime numbers below a given limit."""
  18. return sum(n for n in range(2, limit) if is_prime(n))
  19.  
  20. def nth_prime_below(limit, n):
  21. """Find the nth prime number below a given limit."""
  22. primes = [num for num in range(2, limit) if is_prime(num)]
  23. return primes[n-1] if n <= len(primes) else None
  24.  
  25. # Calculate the sum of prime numbers under 1000
  26. sum_primes = sum_of_primes_below(1000)
  27.  
  28. # Find the 10th prime number under 1000
  29. tenth_prime = nth_prime_below(1000, 10)
  30.  
  31. sum_primes, tenth_prime
Success #stdin #stdout 0.03s 9576KB
stdin
Standard input is empty
stdout
Standard output is empty