Advertisement
serega1112

goldbach

Jan 13th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import math
  2.  
  3. n = int(input())
  4.  
  5. def primes(n):
  6.     res = []
  7.     nums = [True] * (n + 1)
  8.     for i in range(2, n + 1):
  9.         if nums[i]:
  10.             res.append(i)
  11.             j = i**2
  12.             while i < math.floor(n**0.5) + 1 and j < n + 1:
  13.                 nums[j] = False
  14.                 j += i
  15.     return res
  16.  
  17. res = None
  18. nums = primes(n)
  19. s = set()
  20. for num in nums:
  21.     if num == n - num or n - num in s:
  22.         res = f'{num} {n - num}'
  23.         break
  24.     else:
  25.         s.add(num)
  26.        
  27. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement