import Data.Char (chr, ord) intToChar :: Int -> Char intToChar x | 0 <= x && x <= 9 = chr $ ord '0' + x | 10 <= x && x <= 35 = chr $ ord 'A' - 10 + x | otherwise = error "out of range" charToInt :: Char -> Int charToInt c | '0' <= c && c <= '9' = ord c - ord '0' | 'A' <= c && c <= 'Z' = ord c - ord 'A' + 10 | otherwise = error "out of range" toDecimal :: Integral a => Int -> String -> a toDecimal fr fx = sum $ zipWith (\a b -> a * fr' ^ b) fx' $ reverse [0..length fx' - 1] where fx' = dropWhile (== 0) $ map (fromIntegral . charToInt) fx fr' = fromIntegral fr fromDecimal' :: Integral a => a -> Int -> [a] fromDecimal' fx tr | fx < tr' = fx : [] | otherwise = fx `mod` tr' : fromDecimal' (fx `div` tr') tr where tr' = fromIntegral tr fromDecimal :: Integral a => a -> Int -> String fromDecimal fx tr = map (intToChar . fromIntegral) $ reverse $ fromDecimal' fx tr main = do n <- readLn putStrLn $ fromDecimal n 7