Advertisement
miklis

MBK paieškos

Nov 24th, 2015
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #MBK(a,b) -ieskomas maziausias bendras skaiciu a ir b kartotinis
  2. a=15015 #ivesk pirma skaiciu nedidesni uz 100 000 cia
  3. b=1 #ivesk antra skaiciu cia
  4.  
  5. primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331]
  6. def factor(x):
  7. RHS=[]
  8. for n in primes:
  9. while x%n==0:
  10. x/=n
  11. RHS.append(n)
  12. if n**2>x: break
  13. if x>1: RHS.append(x)
  14. return RHS
  15.  
  16. A=factor(a)
  17. B=factor(b)
  18. print "Rasime MBK(a,b)"
  19. print "isskaidome a: a ="," * ".join([str(n) for n in A])
  20. print "isskaidome b: b ="," * ".join([str(n) for n in B])
  21. print "vieno skaidinio papildymas kito elementais:"
  22. C=[[n]*max(A.count(n),B.count(n)) for n in sorted(set(A+B))]
  23. C=reduce(lambda x,y: x+y, C)
  24. print " * ".join([str(n) for n in C])
  25. print "MBK(a,b) = "+" * ".join([str(n) for n in C])+" = "+str(reduce(lambda x,y: x*y, C))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement