• + 0 comments

    Haskell

    So, if you look at the sequence of running XORs over the XORs, there's a pattern. I didn't give it much thought after that -- just implement the lookup function.

    module Main where
    
    import Control.Monad (replicateM_)
    import Data.Bits (xor)
    
    lu :: Int -> Integer
    lu 0 = 1
    lu 1 = 2
    lu 2 = 2
    lu x = do
        let (q, r) = (x - 3) `quotRem` 8
            b = 8 * (fromIntegral q) + 6 :: Integer
         in [b, b + 1, 0, 0, b + 2, b + 3, 2, 2] !! r
    
    solve :: Int -> Int -> Integer
    solve 1 b = lu (b - 1)
    solve a b = xor (lu (a - 2)) (lu (b - 1))
    
    main :: IO ()
    main = do
        cases <- readLn
        replicateM_ cases $ do
            [a, b] <- map read . words <$> getLine
            print $ solve a b