Advertisement
Woobinda

Общие множители

Jul 3rd, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. """
  2. final version
  3. """
  4.  
  5. from functools import reduce
  6.  
  7. def common_factors(*args):
  8.     result = []
  9.     for arg in args:
  10.         result.append([x for x in range(1, arg) if arg % x == 0])
  11.     return sorted(list(reduce(lambda x,y: set(x) & set(y), result)))
  12.  
  13.  
  14. """
  15. version 2
  16. """
  17.  
  18. import time
  19. from functools import reduce
  20.  
  21. def factor(arg):
  22.     result=[]
  23.     for x in range(1,arg+1):
  24.         if arg % x == 0:
  25.             result.append(x)
  26.     return set(result)
  27.  
  28. def common_factor(func, *a):
  29.     arr=list(map(func, a))
  30.     return list(reduce((lambda x,y: x & y), arr))
  31.  
  32.  
  33. """
  34. version 1 (for noobs)
  35. """
  36.  
  37. def f(a):
  38.     m=[]
  39.     A=a+1
  40.     div=list(range(1,A))
  41.     for x in div:
  42.         if a%x==0:
  43.             m+=[x]
  44.     return m
  45.  
  46. def F(*b):
  47.     L=[]
  48.     for x in b:
  49.         L+=[f(x)]
  50.     return L
  51.  
  52. def func(L):
  53.     if len(L)==1:
  54.         return L
  55.     q=len(L)-1
  56.     x=list(set(L[q])&set(L[q-1]))
  57.     return func(L[:-2]+[x])
  58.  
  59. print(func(F(50,40,60)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement