結果

問題 No.377 背景パターン
ユーザー pekempeypekempey
提出日時 2017-02-01 20:18:22
言語 F#
(F# 4.0)
結果
AC  
実行時間 2,568 ms / 5,000 ms
コード長 1,538 bytes
コンパイル時間 5,295 ms
コンパイル使用メモリ 159,744 KB
実行使用メモリ 25,204 KB
最終ジャッジ日時 2023-08-25 17:04:27
合計ジャッジ時間 13,172 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
22,976 KB
testcase_01 AC 89 ms
23,104 KB
testcase_02 AC 89 ms
25,184 KB
testcase_03 AC 88 ms
23,044 KB
testcase_04 AC 87 ms
23,116 KB
testcase_05 AC 87 ms
21,044 KB
testcase_06 AC 88 ms
25,112 KB
testcase_07 AC 88 ms
23,044 KB
testcase_08 AC 89 ms
25,204 KB
testcase_09 AC 88 ms
23,116 KB
testcase_10 AC 89 ms
25,144 KB
testcase_11 AC 88 ms
25,004 KB
testcase_12 AC 88 ms
25,172 KB
testcase_13 AC 102 ms
25,088 KB
testcase_14 AC 102 ms
23,072 KB
testcase_15 AC 89 ms
23,108 KB
testcase_16 AC 2,452 ms
23,176 KB
testcase_17 AC 2,568 ms
25,080 KB
testcase_18 AC 90 ms
23,068 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

/home/judge/data/code/Main.fs(45,9): warning FS0025: Incomplete pattern matches on this expression. For example, the value '[|_; _; _; _|]' may indicate a case not covered by the pattern(s).

ソースコード

diff #

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
0