結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ikdikd
提出日時 2020-06-06 19:46:10
言語 F#
(F# 4.0)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 5,018 ms
コンパイル使用メモリ 165,504 KB
実行使用メモリ 27,212 KB
最終ジャッジ日時 2023-08-25 01:48:52
合計ジャッジ時間 7,177 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
25,164 KB
testcase_01 AC 94 ms
25,140 KB
testcase_02 AC 95 ms
25,096 KB
testcase_03 AC 97 ms
23,056 KB
testcase_04 AC 94 ms
25,072 KB
testcase_05 AC 98 ms
25,200 KB
testcase_06 AC 95 ms
25,176 KB
testcase_07 AC 98 ms
25,212 KB
testcase_08 AC 95 ms
25,152 KB
testcase_09 AC 98 ms
25,180 KB
testcase_10 AC 99 ms
25,156 KB
testcase_11 AC 97 ms
25,236 KB
testcase_12 AC 96 ms
25,092 KB
testcase_13 AC 97 ms
27,132 KB
testcase_14 AC 99 ms
27,152 KB
testcase_15 AC 96 ms
27,212 KB
testcase_16 AC 98 ms
25,164 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 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)

let factors n =
    [ for i in 1L .. sqrt n -> i ]
    |> List.filter (fun i -> n % i = 0L)
    |> List.collect (fun i ->
        [ i
          n / i ])
    |> List.sort
    |> List.distinct

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

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

    let b = bs |> List.min
    let a = sqrt (n / b)

    printfn "%d %d" a b
    0
0