結果
問題 | No.638 Sum of "not power of 2" |
ユーザー | はむ吉🐹 |
提出日時 | 2018-01-27 14:44:48 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 576 bytes |
コンパイル時間 | 7,594 ms |
コンパイル使用メモリ | 161,672 KB |
実行使用メモリ | 7,164 KB |
最終ジャッジ日時 | 2023-08-28 18:21:13 |
合計ジャッジ時間 | 7,451 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
7,012 KB |
testcase_01 | AC | 2 ms
7,112 KB |
testcase_02 | AC | 2 ms
7,152 KB |
testcase_03 | AC | 2 ms
7,084 KB |
testcase_04 | AC | 2 ms
7,108 KB |
testcase_05 | AC | 2 ms
7,136 KB |
testcase_06 | AC | 2 ms
7,104 KB |
testcase_07 | AC | 2 ms
7,120 KB |
testcase_08 | AC | 2 ms
7,148 KB |
testcase_09 | AC | 3 ms
7,164 KB |
testcase_10 | AC | 2 ms
7,156 KB |
testcase_11 | AC | 2 ms
7,132 KB |
testcase_12 | AC | 2 ms
7,064 KB |
testcase_13 | AC | 2 ms
7,104 KB |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import Data.Int (Int64) import Text.Printf (printf) findPair :: Integral a => a -> Maybe (a, a) findPair n | null cands = Nothing | otherwise = let a = head cands in Just (a, n - a) where numKs = succ $ floor $ logBase (2.0 :: Double) $ fromIntegral n ps = [2 ^ k | k <- [0 .. numKs - 1]] f x = notElem x ps && notElem (n - x) ps cands = filter f [1 .. min (numKs + 1) (n - 1)] main :: IO () main = do n <- readLn :: IO Int64 case findPair n of Nothing -> putStrLn "-1" Just (a, b) -> printf "%d %d\n" a b