# Divisores Primos 2.0

Oct 23rd, 2015
172
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/usr/bin/env python
2. # -*- coding: UTF-8 -*-
3. __author__ = 'Julio Tentor jtentor@gmail.com, Brian Mayo brianmay.dev@gmail.com'
4.
5.
6. from math import sqrt
7. from functools import reduce
8.
9.
10. def isPrime(number):
11.     if number < 1:
12.         raise ValueError("Error de argumento en esPrimo")
13.     if number == 1 or number == 2:
14.         return True
15.     if number % 2 == 0:
16.         return False
17.     for i in range(3, int(sqrt(number)) + 1, 2):
18.         if number % i == 0:
19.             return False
20.     return True
21.
22.
23. def Show(number, dividers):
24.     print("El numero que buscamos es", number)
25.     print("Divisores", dividers)
26.     for divider in dividers:
27.         print(divider,"+",number,"/",divider,"=",divider + number / divider)
28.
29.
30. def test():
31.     for number in range(10000, 1, -1):
32.         dividers = [1] + [divider for divider in range(2,number) if number % divider == 0] + [number]
33.         if reduce(lambda a, b: a and b, list(map(lambda n: isPrime(n), list(map(lambda d: d + number / d, dividers))))):
34.             Show(number, dividers)
35.             break
36.
37.
38. if __name__ == '__main__': test()