結果

問題 No.6 使いものにならないハッシュ
ユーザー pocaristpocarist
提出日時 2015-09-02 14:48:25
言語 F#
(F# 4.0)
結果
AC  
実行時間 110 ms / 5,000 ms
コード長 1,383 bytes
コンパイル時間 5,274 ms
コンパイル使用メモリ 166,920 KB
実行使用メモリ 31,348 KB
最終ジャッジ日時 2023-10-14 22:55:41
合計ジャッジ時間 9,264 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
25,212 KB
testcase_01 AC 87 ms
23,240 KB
testcase_02 AC 110 ms
29,596 KB
testcase_03 AC 87 ms
25,248 KB
testcase_04 AC 88 ms
25,248 KB
testcase_05 AC 91 ms
25,268 KB
testcase_06 AC 96 ms
27,112 KB
testcase_07 AC 95 ms
23,156 KB
testcase_08 AC 95 ms
27,192 KB
testcase_09 AC 92 ms
25,260 KB
testcase_10 AC 85 ms
25,184 KB
testcase_11 AC 89 ms
25,244 KB
testcase_12 AC 97 ms
27,316 KB
testcase_13 AC 94 ms
23,236 KB
testcase_14 AC 94 ms
23,200 KB
testcase_15 AC 97 ms
27,276 KB
testcase_16 AC 100 ms
25,132 KB
testcase_17 AC 103 ms
27,268 KB
testcase_18 AC 108 ms
29,504 KB
testcase_19 AC 101 ms
29,340 KB
testcase_20 AC 100 ms
29,256 KB
testcase_21 AC 86 ms
23,196 KB
testcase_22 AC 99 ms
29,420 KB
testcase_23 AC 97 ms
29,432 KB
testcase_24 AC 105 ms
27,276 KB
testcase_25 AC 94 ms
27,176 KB
testcase_26 AC 102 ms
29,344 KB
testcase_27 AC 101 ms
27,240 KB
testcase_28 AC 97 ms
25,248 KB
testcase_29 AC 105 ms
29,424 KB
testcase_30 AC 101 ms
27,284 KB
testcase_31 AC 102 ms
31,348 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 dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt

let primes n =
    let mid = float n |> sqrt |> floor |> int
    let table = Array.init (n+1) (fun _ -> true)
    seq {
        for i in 2 .. mid do
            if table.[i] then
                yield i
                for j in (i+i) .. i .. n do
                    table.[j] <- false
        for i in (mid+1) .. n do
            if table.[i] then
                yield i
    }

let sum_digit n =
    let rec f acc i =
        let m = i % 10
        let d = i / 10
        let acc' = acc+m
        if d = 0 then
            if acc' < 10 then acc'
            else f 0 acc'
        else
            f acc' d
    f 0 n

[<EntryPoint>]
let main argv = 
    let K = Console.ReadLine() |> int
    let N = Console.ReadLine() |> int

    primes N
    |> Seq.filter (fun x -> x >= K)
    |> Seq.toArray
    |> fun ps ->
        let hash = Array.map sum_digit ps
        let rec loop ans maxcnt j =
            if j = hash.Length then ans else
            let rec f s i =
                if i = hash.Length || Set.exists ((=) hash.[i]) s then s.Count
                else f (Set.add hash.[i] s) (i+1)
            let cnt = f Set.empty j
            if cnt >= maxcnt then
                loop ps.[j] cnt (j+1)
            else 
                loop ans maxcnt (j+1)
        loop 0 0 0

    |> printfn "%d"
    0
0