結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー norioc
提出日時 2025-06-29 21:56:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 182 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 101,572 KB
最終ジャッジ日時 2025-06-29 21:56:55
合計ジャッジ時間 3,513 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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():
    aa = Counter([gcd(a, K) for a in A])
    bb = Counter([gcd(b, K) for b in B])
    res = 0
    for k1, v1 in aa.items():
        for k2, v2 in bb.items():
            if k1 * k2 % K == 0:
                res += v1 * v2

    return res


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