• + 0 comments

    Haskell

    module Main where
    
    import Data.Bits
    
    countZeroBits :: Integer -> Int
    countZeroBits n = go n 0
      where
        go :: Integer -> Int -> Int
        go 0 acc = acc
        go n acc = go (n `shiftR` 1) (acc + 1 - fromIntegral (n .&. 1))
    
    solve :: Integer -> Integer
    solve n = 1 `shiftL` countZeroBits n
    
    main :: IO ()
    main = readLn >>= print . solve