Advertisement
Guest User

Untitled

a guest
Nov 25th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import sys
  2. from time import time
  3. from math import sqrt
  4. with open('test_file.txt', 'w', encoding='utf-8') as f:
  5.     sys.stdout = f
  6.     n= int(input())
  7.     start_time = time()
  8.     numb = {k for k in range(2,n+1)}
  9.     for k in range (2, int(sqrt(n))+2):
  10.             if  k not in numb:
  11.                 continue
  12.             else:
  13.                 for r in range (2*k, n+1,k):
  14.                     numb.discard(r)
  15.     print(numb)
  16.     print('--- %s seconds ---' % (time() - start_time))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement