結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
31,740 KB
testcase_01 AC 100 ms
25,424 KB
testcase_02 AC 100 ms
25,280 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 1 .. n -> i
    }
    |> Seq.filter (fun i -> i * i <= n && n % i = 0)
    |> 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 <= 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 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