結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー kuuso1
提出日時 2016-08-27 17:29:17
言語 F#
(F# 4.0)
結果
AC  
実行時間 347 ms / 1,000 ms
コード長 769 bytes
コンパイル時間 7,062 ms
コンパイル使用メモリ 209,836 KB
実行使用メモリ 34,832 KB
最終ジャッジ日時 2024-11-08 19:35:40
合計ジャッジ時間 21,414 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (234 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
/home/judge/data/code/Main.fs(19,13): warning FS0025: この式のパターン マッチが不完全です たとえば、値 '[|_; _; _; _|]' はパターンに含まれないケースを示す可能性があります。 [/home/judge/data/code/main.fsproj]
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

open System

let ri () = stdin.ReadLine() |> int
let ria () = stdin.ReadLine().Split() |> Array.map int
let rl () = stdin.ReadLine() |> int64
let rla () = stdin.ReadLine().Split() |> Array.map int64

let rec gcd (s:int64) (t:int64) :int64 =
    match s with
    | 0L -> t
    | _ -> gcd (t%s) s

let lcm (s:int64) (t:int64) :int64 = s * t / (gcd s t)

type Sol() =
    member this.Solve() = 
        
        let N = rl () 
        let [|a; b; c|] = rla ()
        
        let mutable sum = N
        sum <- [a;b;c] |> Seq.sumBy (fun x -> N/x ) 
        sum <- sum - ([(a,b);(b,c);(c,a)] |> Seq.sumBy (fun (x,y) -> N / (lcm x y) ) )
        sum <- sum + (N / (Seq.reduce lcm [a;b;c])) 
        
        sum |> printfn "%d"
        
let mySol = new Sol()
mySol.Solve()
0