Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
45
Task/Parallel-calculations/Python/parallel-calculations-1.py
Normal file
45
Task/Parallel-calculations/Python/parallel-calculations-1.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
from concurrent import futures
|
||||
from math import floor, sqrt
|
||||
|
||||
NUMBERS = [
|
||||
112272537195293,
|
||||
112582718962171,
|
||||
112272537095293,
|
||||
115280098190773,
|
||||
115797840077099,
|
||||
1099726829285419]
|
||||
# NUMBERS = [33, 44, 55, 275]
|
||||
|
||||
def lowest_factor(n, _start=3):
|
||||
if n % 2 == 0:
|
||||
return 2
|
||||
search_max = int(floor(sqrt(n))) + 1
|
||||
for i in range(_start, search_max, 2):
|
||||
if n % i == 0:
|
||||
return i
|
||||
return n
|
||||
|
||||
def prime_factors(n, lowest):
|
||||
pf = []
|
||||
while n > 1:
|
||||
pf.append(lowest)
|
||||
n //= lowest
|
||||
lowest = lowest_factor(n, max(lowest, 3))
|
||||
return pf
|
||||
|
||||
def prime_factors_of_number_with_lowest_prime_factor(NUMBERS):
|
||||
with futures.ProcessPoolExecutor() as executor:
|
||||
low_factor, number = max( (l, f) for l, f in zip(executor.map(lowest_factor, NUMBERS), NUMBERS) )
|
||||
all_factors = prime_factors(number, low_factor)
|
||||
return number, all_factors
|
||||
|
||||
|
||||
def main():
|
||||
print('For these numbers:')
|
||||
print('\n '.join(str(p) for p in NUMBERS))
|
||||
number, all_factors = prime_factors_of_number_with_lowest_prime_factor(NUMBERS)
|
||||
print(' The one with the largest minimum prime factor is {}:'.format(number))
|
||||
print(' All its prime factors in order are: {}'.format(all_factors))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
46
Task/Parallel-calculations/Python/parallel-calculations-2.py
Normal file
46
Task/Parallel-calculations/Python/parallel-calculations-2.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import multiprocessing
|
||||
|
||||
# ========== #Python3 - concurrent
|
||||
from math import floor, sqrt
|
||||
|
||||
numbers = [
|
||||
112272537195293,
|
||||
112582718962171,
|
||||
112272537095293,
|
||||
115280098190773,
|
||||
115797840077099,
|
||||
1099726829285419]
|
||||
# numbers = [33, 44, 55, 275]
|
||||
|
||||
def lowest_factor(n, _start=3):
|
||||
if n % 2 == 0:
|
||||
return 2
|
||||
search_max = int(floor(sqrt(n))) + 1
|
||||
for i in range(_start, search_max, 2):
|
||||
if n % i == 0:
|
||||
return i
|
||||
return n
|
||||
|
||||
def prime_factors(n, lowest):
|
||||
pf = []
|
||||
while n > 1:
|
||||
pf.append(lowest)
|
||||
n //= lowest
|
||||
lowest = lowest_factor(n, max(lowest, 3))
|
||||
return pf
|
||||
# ========== #Python3 - concurrent
|
||||
|
||||
def prime_factors_of_number_with_lowest_prime_factor(numbers):
|
||||
pool = multiprocessing.Pool(processes=5)
|
||||
factors = pool.map(lowest_factor,numbers)
|
||||
|
||||
low_factor,number = max((l,f) for l,f in zip(factors,numbers))
|
||||
all_factors = prime_factors(number,low_factor)
|
||||
return number,all_factors
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('For these numbers:')
|
||||
print('\n '.join(str(p) for p in numbers))
|
||||
number, all_factors = prime_factors_of_number_with_lowest_prime_factor(numbers)
|
||||
print(' The one with the largest minimum prime factor is {}:'.format(number))
|
||||
print(' All its prime factors in order are: {}'.format(all_factors))
|
||||
Loading…
Add table
Add a link
Reference in a new issue