= 1 || $now < 1) { $count = -1; break; } $hist[] = $now; // 計算 $move = mb_substr_count(decbin($now), "1"); if ($now + $move <= $N) { $now += $move; } else { $now -= $move; } $count++; } echo $count . "\n";