結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー ikdikd
提出日時 2020-06-06 19:50:10
言語 F#
(F# 4.0)
結果
TLE  
実行時間 -
コード長 829 bytes
コンパイル時間 3,687 ms
コンパイル使用メモリ 164,912 KB
実行使用メモリ 27,336 KB
最終ジャッジ日時 2023-08-25 01:49:25
合計ジャッジ時間 8,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
27,316 KB
testcase_01 AC 101 ms
25,244 KB
testcase_02 AC 101 ms
27,336 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 factors n =
    seq {
        for i in 1L .. n -> i
    }
    |> Seq.filter (fun i -> i * i <= n && 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