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(limit):
  17. """Calculate the sum of the first 'limit' prime numbers."""
  18. prime_count = 0
  19. num = 2
  20. prime_sum = 0
  21. while prime_count < limit:
  22. if is_prime(num):
  23. prime_sum += num
  24. prime_count += 1
  25. num += 1
  26. return prime_sum
  27.  
  28. # Calculate the sum of the first 200 prime numbers
  29. sum_200_primes = sum_of_primes(200)
  30. print("The sum of the first 200 prime numbers is:", sum_200_primes)
Success #stdin #stdout 0.03s 9584KB
stdin
Standard input is empty
stdout
The sum of the first 200 prime numbers is: 111587