結果

問題 No.300 平方数
ユーザー Leonardone
提出日時 2015-11-16 06:38:44
言語 Haskell
(9.10.1)
結果
TLE  
実行時間 -
コード長 446 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 169,728 KB
実行使用メモリ 17,824 KB
最終ジャッジ日時 2024-09-13 15:23:59
合計ジャッジ時間 4,428 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 TLE * 1
other -- * 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 )
[2 of 2] Linking a.out

ソースコード

diff #

-- yukicoder My Practice
-- author: Leonardone @ NEETSDKASU

import Control.Applicative
import Data.List

main = readLn >>= \n -> print $ (!! 1) $ foldl g [n, 1] $ takeWhile (<= n) $ primes [2..] where
    f (x, c) p
        | mod x p == 0 = f (div x p, c + 1) p
        | mod c 2 == 0 = [x, 1]
        | otherwise    = [x, p]
    g (x:c:_) p = zipWith (*) [1, c] $ f (x, 0) p

primes [] = []
primes (x:xs) = x : primes [p | p <- xs, mod p x > 0]
0