結果
問題 | No.300 平方数 |
ユーザー |
|
提出日時 | 2016-04-23 14:40:39 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 56 ms / 1,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 1,729 ms |
コンパイル使用メモリ | 172,624 KB |
実行使用メモリ | 8,064 KB |
最終ジャッジ日時 | 2024-10-04 15:19:27 |
合計ジャッジ時間 | 3,122 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:7:1: warning: [GHC-94817] [-Wtabs] Tab character found here, and in 24 further locations. Suggested fix: Please use spaces instead. | 7 | if n `mod` 2 == 0 | ^^^^^^^^ Main.hs:29:87: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 29 | print $ (product . concat . map (\x -> if mod (length x) 2 == 0 then [] else [head x]) . group . primefact) n | ^^^^ [2 of 2] Linking a.out
ソースコード
import Data.List isprime :: Integer -> Bool isprime 1 = False isprime 2 = True isprime n = if n `mod` 2 == 0 then False else and [ n `mod` i /= 0 | i <- [3,5..sq] ] where sq = (floor . sqrt . fromIntegral) n primefact' :: Integer -> Integer -> [Integer] primefact' 1 _ = [1] primefact' n p = if n `mod` p == 0 then if isprime (n `div` p) then p : [n `div` p] else p : primefact' (n `div` p) p else primefact' n (p + 1) primefact :: Integer -> [Integer] primefact n = if isprime n then [n] else primefact' n 2 main = do n <- readLn print $ (product . concat . map (\x -> if mod (length x) 2 == 0 then [] else [head x]) . group . primefact) n