prime.py 640 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # coding: utf-8
  2. import math
  3. def sum_digits(n):
  4. sum = 0
  5. while n > 0:
  6. sum += n % 10
  7. n = int(n / 10)
  8. return sum
  9. def is_prime(n):
  10. if n % 2 == 0 and n > 2:
  11. return False
  12. for i in range(3, int(math.sqrt(n)) + 1, 2):
  13. if n % i == 0:
  14. return False
  15. return True
  16. def next_prime(n):
  17. if n % 2 == 0:
  18. n += 1
  19. else:
  20. n += 2
  21. while not is_prime(n):
  22. n += 2
  23. return n
  24. a = next_prime(1000000)
  25. while not is_prime(sum_digits(a)):
  26. a = next_prime(a)
  27. b = next_prime(a)
  28. while not is_prime(sum_digits(b)):
  29. b = next_prime(b)
  30. print(str(a) + str(b))