2013-04-17 14:34:39 +08:00

40 lines
729 B
Python

gcd = lambda x, y: y == 0 and x or gcd(y, x % y)
def common(x, y):
a = []
b = []
while x > 0:
a.append(x % 10)
x /= 10
while y > 0:
b.append(y % 10)
y /= 10
outa = 0
outb = 0
tmp = list(set(a) & set(b))
if tmp.count(0) != 0:
tmp.remove(0)
if len(tmp) > 0:
for i in tmp:
a.remove(i)
b.remove(i)
if len(a) == 0 or len(b) == 0:
return (False, 0)
a.reverse()
for j in a: outa = outa * 10 + j
b.reverse()
for j in b: outb = outb * 10 + j
return (True, outa, outb)
else:
return (False, 0)
for i in xrange(11, 100):
for j in xrange(i + 1, 100):
tmp = common(i, j)
if tmp[0]:
if tmp[1] * j == tmp[2] * i:
print i, j