-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpe5.py
50 lines (43 loc) · 1.44 KB
/
pe5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'''What is the smallest positive number that is evenly divisible(divisible with no remainder)
by all of the numbers from 1 to N?'''
from collections import Counter
from math import sqrt
from functools import reduce
def isPrime(n):
'''
Indica si el numero n es primo
:param n:
:return:
'''
return all([n%i != 0 for i in range(2, int(sqrt(n))+1)])
def factorizacion(num):
'''
Devuelve un Counter con los factores primos del numero num y la cantidad de cada uno
:param num:
:return: Counter
'''
factores, flag = [], True
while(flag):
flag = False
for i in range(2, num+1):
if num%i == 0 and isPrime(i):
num = num//i
flag = True
factores.append(i)
return Counter(factores)
def obtenerPrimos(n):
'''
Devuelve un Counter con todos los factores primos de los numeros menores a n
la cantidad de cada factor primo es la mayor de todas
:param n:
:return: Counter
'''
primos = Counter()
for i in range(n+1):
for (factor, cantidad) in factorizacion(i).items():
primos[factor] = cantidad if primos[factor] < cantidad else primos[factor]
return primos
for _ in range(int(input())):
primos = obtenerPrimos(int(input())) #Obtengo los factores primos que forman el numero buscado
#print(primos)
print(reduce(lambda x, y: x*y, primos.elements(), 1)) # Multiplico todos los factores