Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #MBK(a,b) -ieskomas maziausias bendras skaiciu a ir b kartotinis
- x="3/5 + 7/20" #ivesk trupmenu suma arba skirtuma
- 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]
- def factor(x):
- RHS=[]
- for n in primes:
- while x%n==0:
- x/=n
- RHS.append(n)
- if n**2>x: break
- if x>1: RHS.append(x)
- return RHS
- def MBK(a,b):
- A=factor(a)
- B=factor(b)
- C=[[n]*max(A.count(n),B.count(n)) for n in sorted(set(A+B))]
- C=reduce(lambda x,y: x+y, C)
- return reduce(lambda x,y: x*y, C)
- A=x.index('/')
- if '+' in x: B=x.index('+')
- if '-' in x: B=x.index('-')
- C=B+1+x[B+1:].index('/')
- a=int(x[:A])
- b=int(x[A+1:B])
- c=int(x[B+1:C])
- d=int(x[C+1:])
- t=MBK(b,d)
- a1=t/b
- a2=t/d
- print x+ " = "+str(a1*a)+'/'+str(t)+' '+ x[B]+str(a2*c)+'/'+str(t)
- if '+' in x: print " = "+str(a1*a+a2*c)+ "/" + str(t)
- if '-' in x: print " = "+str(a1*a-a2*c)+ "/" + str(t)
- print "bendras vardiklis: "+str(t)
- print "daugiklis pirmai trupmenai:",str(a1)
- print "daugiklis antrai trupmenai:",str(a2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement