結果
問題 |
No.6 使いものにならないハッシュ
|
ユーザー |
![]() |
提出日時 | 2015-09-02 14:48:25 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 390 ms / 5,000 ms |
コード長 | 1,383 bytes |
コンパイル時間 | 11,608 ms |
コンパイル使用メモリ | 186,328 KB |
実行使用メモリ | 42,920 KB |
最終ジャッジ日時 | 2024-09-16 16:30:08 |
合計ジャッジ時間 | 23,603 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (447 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
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