結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ikdikd
提出日時 2020-06-06 19:36:39
言語 F#
(F# 4.0)
結果
TLE  
実行時間 -
コード長 812 bytes
コンパイル時間 5,588 ms
コンパイル使用メモリ 164,864 KB
実行使用メモリ 25,452 KB
最終ジャッジ日時 2023-08-25 01:47:32
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
25,276 KB
testcase_01 AC 99 ms
25,452 KB
testcase_02 AC 98 ms
25,328 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System

let sqrt n =
    let rec solve sm bg = // sm * sm <= n < bg * bg
        if bg - sm <= 1 then
            sm
        else
            let mid = (bg + sm) / 2
            if mid * mid <= n then solve mid bg else solve sm mid
    solve 0 (n + 1)

let factors n =
    seq {
        for i in 1 .. sqrt n -> i
    }
    |> Seq.filter (fun i -> n % i = 0)
    |> Seq.collect (fun i ->
        seq {
            yield i
            yield n / i
        })
    |> Seq.sort
    |> Seq.distinct

[<EntryPoint>]
let main _ =
    let n = stdin.ReadLine() |> int

    let bs =
        factors n
        |> Seq.filter (fun b ->
            let m = (n / b)
            (sqrt m) * (sqrt m) = m)

    let b =
        bs
        |> Seq.sort
        |> Seq.head

    let a = sqrt (n / b)

    printfn "%d %d" a b
    0
0