$lcm = $r * 4096; $lcm /= 2 until $lcm % 8192; $c = int( $s/$lcm) * $lcm;