結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ikdikd
提出日時 2020-06-06 20:16:58
言語 F#
(F# 4.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 858 bytes
コンパイル時間 3,648 ms
コンパイル使用メモリ 160,912 KB
実行使用メモリ 27,352 KB
最終ジャッジ日時 2023-08-25 01:52:13
合計ジャッジ時間 6,518 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
23,236 KB
testcase_01 AC 99 ms
23,200 KB
testcase_02 AC 99 ms
25,180 KB
testcase_03 AC 103 ms
25,332 KB
testcase_04 AC 101 ms
25,240 KB
testcase_05 AC 103 ms
25,304 KB
testcase_06 AC 103 ms
27,244 KB
testcase_07 AC 104 ms
27,260 KB
testcase_08 AC 103 ms
27,296 KB
testcase_09 AC 103 ms
25,300 KB
testcase_10 AC 105 ms
25,260 KB
testcase_11 AC 103 ms
25,232 KB
testcase_12 AC 103 ms
25,248 KB
testcase_13 AC 103 ms
25,364 KB
testcase_14 AC 103 ms
25,196 KB
testcase_15 AC 103 ms
27,352 KB
testcase_16 AC 103 ms
25,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System

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

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

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

    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