結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー norioc
提出日時 2025-06-29 21:53:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,385 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 82,380 KB
実行使用メモリ 101,448 KB
最終ジャッジ日時 2025-06-29 21:53:34
合計ジャッジ時間 6,555 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from math import gcd

N, M, K = map(int, input().split())
s = input().split()
op = s[0]
B = [int(x) for x in s[1:]]
A = []
for _ in range(N):
    A.append(int(input()))


def calc_add():
    bb = Counter([b % K for b in B])
    res = 0
    for a in A:
        x = (K - a) % K
        res += bb[x]

    return res


def calc_mul():
    bb = Counter([gcd(b, K) for b in B])
    res = 0
    for a in A:
        x = gcd(a, K)
        for k, v in bb.items():
            if x * k % K == 0:
                res += v

    return res


if op == '+':
    print(calc_add())
else:
    print(calc_mul())
0