-- Copyright (C) 2014 by Alexandru Cojocaru -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation, either version 3 of the License, or -- (at your option) any later version. -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- You should have received a copy of the GNU General Public License -- along with this program. If not, see . import Data.List import qualified Data.ByteString.Char8 as C import Data.Maybe maxn :: Integral a => a maxn = 1000000 aritsum :: Integral a => a -> a aritsum k = k*(k+1) `div` 2 sqssum :: Integral a => a -> a sqssum n = (2*n^3 + 3*n^2 + n) `div` 6 xy :: Integral a => a -> a -> (a,a) xy dsum dsqsum = ((dsum + delta) `div` 2, (dsum - delta) `div` 2) where delta = (truncate . sqrt . fromIntegral) (2*dsqsum - dsum*dsum) dsums = foldl' (\(dsum,dsqsum) n -> (dsum-n,dsqsum-n*n)) (aritsum maxn, sqssum maxn) sol = C.pack . show . (uncurry xy) . dsums . (map $ fst . fromJust . C.readInteger) . C.lines main = C.interact sol