結果

問題 No.648  お や す み 
ユーザー tak
提出日時 2018-04-12 10:02:58
言語 F#
(F# 4.0)
結果
WA  
実行時間 -
コード長 577 bytes
コンパイル時間 6,729 ms
コンパイル使用メモリ 194,880 KB
実行使用メモリ 34,784 KB
最終ジャッジ日時 2024-06-26 21:23:28
合計ジャッジ時間 15,289 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 53 WA * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (237 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/

ソースコード

diff #

let rec sqrt n guess =
    let curGuess =
        match guess with
        | None    -> n / 2m
        | Some(x) -> x
    let res = n / curGuess
    let ave = (curGuess + res) / 2m
    if ave = curGuess then ave
    else sqrt n (Some(ave))

let isInt (n:decimal) =
    let str = n.ToString().Split('.')
    str.Length > 1 &&
    str.[1].ToCharArray() |> Array.forall(fun x -> x ='0')

let isValid n =
    let f n = ((sqrt (8m * n + 1m) None )-1m)/2m
    f n |> isInt
    
let n = stdin.ReadLine() |> decimal

n
|> isValid
|> function | true -> "YES" | _ -> "NO"
|> printfn "%s"
0