Add Python notes
This commit is contained in:
88
python/функции/NOK2.py
Executable file
88
python/функции/NOK2.py
Executable file
@@ -0,0 +1,88 @@
|
||||
import operator
|
||||
import functools
|
||||
prime = [2, 3]
|
||||
|
||||
def simple(a):
|
||||
num = a[-1]+1
|
||||
tr = False
|
||||
while tr != True:
|
||||
for i in range(2, num):
|
||||
if num%i == 0:
|
||||
tr = False
|
||||
num += 1
|
||||
break
|
||||
else:
|
||||
tr = True
|
||||
a.append(num)
|
||||
# print(f'В список добавлено число {num}')
|
||||
|
||||
|
||||
|
||||
def NOK(x,y):
|
||||
if x > y:
|
||||
difx = True
|
||||
else:
|
||||
difx=False
|
||||
|
||||
arrayx=[]
|
||||
arrayy=[]
|
||||
counter=0
|
||||
while x!=1:
|
||||
for i in range(counter, len(prime)):
|
||||
if prime[i]>(x/2):
|
||||
arrayx.append(x)
|
||||
x=1
|
||||
break
|
||||
if x%prime[i]==0:
|
||||
x //= prime[i]
|
||||
arrayx.append(prime[i])
|
||||
counter=0
|
||||
i=0
|
||||
break
|
||||
|
||||
if (x>1) and (i==(len(prime)-1)):
|
||||
simple(prime)
|
||||
counter=i
|
||||
|
||||
counter=0
|
||||
while y!=1:
|
||||
for i in range(counter, len(prime)):
|
||||
if prime[i]>(y/2):
|
||||
arrayy.append(y)
|
||||
y=1
|
||||
break
|
||||
if y%prime[i]==0:
|
||||
y//=prime[i]
|
||||
arrayy.append(prime[i])
|
||||
counter=0
|
||||
i=0
|
||||
break
|
||||
|
||||
if (y>1) and (i==(len(prime)-1)):
|
||||
simple(prime)
|
||||
counter=i
|
||||
|
||||
print(arrayx, arrayy)
|
||||
|
||||
count_ax = 0
|
||||
y_second = list(arrayy)
|
||||
x_second = list(arrayx)
|
||||
for i in range(0, len(arrayy)):
|
||||
for for_x in range(0, len(x_second)):
|
||||
if arrayy[i] == x_second[for_x]:
|
||||
y_second.remove(arrayy[i])
|
||||
x_second.remove(arrayy[i])
|
||||
break
|
||||
|
||||
|
||||
result_array = y_second + arrayx
|
||||
result = functools.reduce(operator.mul, result_array, 1)
|
||||
print(result_array, result)
|
||||
return result
|
||||
|
||||
|
||||
|
||||
first = int(input())
|
||||
second = int(input())
|
||||
print(NOK(first,second))
|
||||
input()
|
||||
Reference in New Issue
Block a user