Simple. If one of the numbers is not a factor of the other number, then you multiply them together.

or in programming (vb)
if a mod b = 0 then
if a >= b then c = a else c = b
else
c = a * b
end if
msgbox "pattern repeats every " & c & "bytes"