結果

問題 No.278 連続する整数の和(2)
ユーザー HaarHaar
提出日時 2016-04-23 00:16:31
言語 Haskell
(9.6.2)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 681 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 164,192 KB
実行使用メモリ 11,220 KB
最終ジャッジ日時 2023-08-24 22:47:26
合計ジャッジ時間 2,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,084 KB
testcase_01 AC 2 ms
7,020 KB
testcase_02 AC 32 ms
11,220 KB
testcase_03 AC 2 ms
7,016 KB
testcase_04 AC 3 ms
7,096 KB
testcase_05 AC 3 ms
7,228 KB
testcase_06 AC 2 ms
7,164 KB
testcase_07 AC 3 ms
7,084 KB
testcase_08 AC 2 ms
7,112 KB
testcase_09 AC 3 ms
7,020 KB
testcase_10 AC 3 ms
7,496 KB
testcase_11 AC 22 ms
11,096 KB
testcase_12 AC 3 ms
7,020 KB
testcase_13 AC 52 ms
11,164 KB
testcase_14 AC 6 ms
9,352 KB
testcase_15 AC 22 ms
11,196 KB
testcase_16 AC 7 ms
10,188 KB
testcase_17 AC 5 ms
9,216 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 )

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
  | ^^^^^^^^
[2 of 2] Linking a.out

ソースコード

diff #

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 = ceiling (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
	let p = if n `mod` 2 == 1 then n else n `div` 2
	print $ (product . map (sum . nub . scanl1 (*) . (1:)) . group . primefact) p
0