open System.Collections let ``No.3 ビットすごろく`` () = let bitcount (bit:int) = let a = (bit &&& 0x55555555) + (bit >>> 1 &&& 0x55555555) in let b = (a &&& 0x33333333) + (a >>> 2 &&& 0x33333333) in let c = (b &&& 0x0F0F0F0F) + (b >>> 4 &&& 0x0F0F0F0F) in let d = (c &&& 0x00FF00FF) + (c >>> 8 &&& 0x00FF00FF) in (d &&& 0x0000FFFF) + (d >>> 16 &&& 0x0000FFFF) let N = int <| stdin.ReadLine() let bits = [| yield 1; for i in 1..N -> bitcount i |] let cash = new BitArray(N) let rec s p = seq { let np = p + bits.[p] if np = N then yield np elif N < np then let nm = p - bits.[p] if 1 <= nm && not(cash.[nm]) then cash.[nm] <- true yield nm yield! s nm else failwith "-1" else cash.[np] <- true yield np yield! s np } try s 0 |> Seq.length with | _ -> -1 |> printfn "%d" ``No.3 ビットすごろく`` ()