• + 0 comments

    Haskell:

    Weird one.

    module Main where
    
    import Data.List (splitAt)
    
    test :: Int -> Bool
    test n = do
        let sn = show $ n ^ 2
        let len = length sn
        let (l, r) = splitAt (len `div` 2) sn
        let l' = if null l then 0 else read l :: Int
        let r' = if null r then 0 else read r :: Int
        n == l' + r'
    
    solve :: Int -> Int -> [Int]
    solve p q = filter test [p .. q]
    
    main :: IO ()
    main = do
        p <- readLn :: IO Int
        q <- readLn :: IO Int
        putStrLn $ do
            let ks = solve p q
            if null ks
                then "INVALID RANGE"
                else unwords $ map show $ solve p q