Skip to content

Только тексты программы #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Lesson_4/Resheto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#-------------------------------------------------------------------------------
# Name: Resheto_Erisphena
# Purpose:
#
# Author: Yuri Nesterovich
#
# Created: 06.04.2019
# Copyright: (c) Fujitsu 2019
# Licence: <your licence>
#-------------------------------------------------------------------------------

def primes(n):
a = [0] * n
for i in range(n):
a[i] = i

a[1] = 0

m = 2 # замена на 0 начинается с 3-го элемента (первые два уже нули)
while m < n: # перебор всех элементов до заданного числа
if a[m] != 0: # если он не равен нулю, то
j = m * 2 # увеличить в два раза (текущий элемент простое число)
while j < n:
a[j] = 0 # заменить на 0
j = j + m # перейти в позицию на m больше
m += 1


b = []
for i in a:
if a[i] != 0:
b.append(a[i])

del a
return b
23 changes: 23 additions & 0 deletions Lesson_4/find_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#-------------------------------------------------------------------------------
# Name: find_simple
# Purpose:
#
# Author: Fujitsu
#
# Created: 06.04.2019
# Copyright: (c) Fujitsu 2019
# Licence: <your licence>
#-------------------------------------------------------------------------------
from math import sqrt

def foo():
list = set()
for i in range(300):
for j in range(2, 1 + int(sqrt(i))):
if not i % j:
break
else:
list.add(i)
print(list)

foo()