const FACTOR_A = 16807;
const FACTOR_B = 48271;
const DIVISOR = 2147483647;
CONST BITMASK_16 = 0xFFFF;
// ==================================================
// > PART 1
// ==================================================
[$a, $b] = $input->numbers;
$solution_1 = 0;
for ($i = 0; $i <= 40_000_000; $i++) {
$a = ($a * FACTOR_A) % DIVISOR;
$b = ($b * FACTOR_B) % DIVISOR;
if (($a & BITMASK_16) === ($b & BITMASK_16)) $solution_1++;
}
// ==================================================
// > PART 2
// ==================================================
[$a, $b] = $input->numbers;
$solution_2 = 0;
for ($i = 0; $i <= 5_000_000; $i++) {
do {
$a = ($a * FACTOR_A) % DIVISOR;
} while ($a % 4 !== 0);
do {
$b = ($b * FACTOR_B) % DIVISOR;
} while ($b % 8 !== 0);
if (($a & BITMASK_16) === ($b & BITMASK_16)) $solution_2++;
}