結果
問題 |
No.377 背景パターン
|
ユーザー |
|
提出日時 | 2017-02-01 20:18:22 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 2,716 ms / 5,000 ms |
コード長 | 1,538 bytes |
コンパイル時間 | 15,840 ms |
コンパイル使用メモリ | 210,340 KB |
実行使用メモリ | 35,252 KB |
最終ジャッジ日時 | 2024-12-24 02:20:29 |
合計ジャッジ時間 | 29,075 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 14 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (430 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) /home/judge/data/code/Main.fs(45,9): 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/
ソースコード
let modulo = 1000000007 let moduloL = int64 modulo let ( ++ ) a b = if a + b >= modulo then a + b - modulo else a + b let ( -- ) a b = a ++ (modulo - b) let ( ** ) a b = (int64 a) * (int64 b) % moduloL |> int 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 modpow x y = let rec f x y acc = if y = 0L then acc else let acc = if y % 2L = 0L then acc else acc ** x f (x ** x) (y / 2L) acc f x y 1 let modinv x = modpow x (moduloL - 2L) let divisors n = let mutable i = 1 let mutable ret = [] while i * i <= n do if n % i = 0 then ret <- i :: ret if i * i <> n then ret <- (n / i) :: ret i <- i + 1 ret |> List.toArray |> Array.sort let gcdnum n = let ds = divisors n let s = Array.map (fun d -> n / d) ds let n = Array.length ds for i in n - 1 .. -1 .. 0 do for j in 0 .. i - 1 do if ds.[i] % ds.[j] = 0 then s.[j] <- s.[j] -- s.[i] Array.zip ds s do let [|h; w; k|] = stdin.ReadLine().Split() |> Array.map int let hh = gcdnum h let ww = gcdnum w let mutable ans = 0 for d1, s1 in hh do for d2, s2 in ww do let h = int64 h let w = int64 w let d1 = int64 d1 let d2 = int64 d2 let t = h * w / lcm (h / d1) (w / d2) ans <- ans ++ (modpow k t) ** s1 ** s2 ans <- ans ** modinv (h ** w) printfn "%d" ans