結果
| 問題 | No.3152 neither multiple of A nor B | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-06-04 17:10:10 | 
| 言語 | F# (F# 4.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 365 ms / 2,000 ms | 
| コード長 | 575 bytes | 
| コンパイル時間 | 9,730 ms | 
| コンパイル使用メモリ | 201,552 KB | 
| 実行使用メモリ | 34,876 KB | 
| 最終ジャッジ日時 | 2025-06-04 17:10:37 | 
| 合計ジャッジ時間 | 25,099 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (317 ミリ秒)。 main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
open System
let input = Console.ReadLine().Split(' ') |> Array.map int64
let n = input.[0]
let a = input.[1]
let b = input.[2]
// Count integers from 0 to N that are neither multiples of A nor multiples of B
let multiples_of_a = n / a + 1L
let multiples_of_b = n / b + 1L
// LCM of A and B
let rec gcd x y = if y = 0L then x else gcd y (x % y)
let lcm x y = x * y / (gcd x y)
let lcm_ab = lcm a b
let multiples_of_both = n / lcm_ab + 1L
// Using inclusion-exclusion principle
let result = (n + 1L) - multiples_of_a - multiples_of_b + multiples_of_both
printfn "%d" result
            
            
            
        