結果
| 問題 |
No.889 素数!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-19 18:00:25 |
| 言語 | F# (F# 4.0) |
| 結果 |
AC
|
| 実行時間 | 341 ms / 2,000 ms |
| コード長 | 1,053 bytes |
| コンパイル時間 | 14,168 ms |
| コンパイル使用メモリ | 189,536 KB |
| 実行使用メモリ | 36,160 KB |
| 最終ジャッジ日時 | 2024-07-03 13:29:48 |
| 合計ジャッジ時間 | 29,488 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (333 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
type Response = Sosu | Heihousu | Rippousu | Kanzensu | Other
let checker n =
let limit = n |> float |> sqrt |> ceil |> int
let rec check i =
if i > limit then
Sosu
elif n % i = 0 then
let mutable j = i
let mutable result = Other
while j <= limit do
if j*j = n then result <- Heihousu elif j*j*j = n then result <- Rippousu
j <- j+ 1
result
else check (i+1)
let isKanzensu n =
if n%2 <> 0 then false
else
let sum = [ for i in 1..(n-1) do if n % i = 0 then yield i ] |> List.sum
sum = n
if n <= 1 then Other
else if n = 2 then Sosu
else if isKanzensu n then Kanzensu
else check 2
let N = stdin.ReadLine().Trim() |> int
match checker N with
| Response.Sosu -> printfn "Sosu!"
| Response.Heihousu -> printfn "Heihosu!"
| Response.Rippousu -> printfn "Ripposu!"
| Response.Kanzensu -> printfn "Kanzensu!"
| Response.Other -> printfn "%d" N