import sys, subprocess, math, getopt
from fractions import Fraction
import sys, subprocess, math, getopt
from fractions import Fraction
# Trivial special case.
return (m, 1, {(m,):n}, {(m,)*(n/m):m})
best = (0,)
# Trivial special case.
return (m, 1, {(m,):n}, {(m,)*(n/m):m})
best = (0,)
result = try_one_minfrag(n, m, k, d)
if result is not None:
best = (Fraction(k, d), d) + result
break
result = try_one_minfrag(n, m, k, d)
if result is not None:
best = (Fraction(k, d), d) + result
break
d = best[1]
print "%d into %d best min fragment found: %s" % (n, m, best[0])
print " Cut up %d sticks of length %d like this:" % (n, m)
d = best[1]
print "%d into %d best min fragment found: %s" % (n, m, best[0])
print " Cut up %d sticks of length %d like this:" % (n, m)
print " %d x (%s)" % (count, " + ".join([str(Fraction(k,d)) for k in row]))
print " Reassemble as %d sticks of length %d like this:" % (m, n)
print " %d x (%s)" % (count, " + ".join([str(Fraction(k,d)) for k in row]))
print " Reassemble as %d sticks of length %d like this:" % (m, n)