結果

問題 No.990 N×Mマス計算(Kの倍数)
コンテスト
ユーザー rin204
提出日時 2022-07-09 15:14:13
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 921 ms / 2,000 ms
コード長 727 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,725 ms
コンパイル使用メモリ 84,608 KB
実行使用メモリ 98,664 KB
最終ジャッジ日時 2026-06-04 12:17:24
合計ジャッジ時間 6,808 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from math import gcd

n, m, k = map(int, input().split())
op, *B = input().split()
B = [int(b) for b in B]
A = [int(input()) for _ in range(n)]
if op == "+":
    cnt = {}
    for b in B:
        cnt[b % k] = cnt.get(b % k, 0) + 1
    ans = 0
    for a in A:
        ans += cnt.get(-a % k, 0)
    print(ans)
else:
    div = []
    for i in range(1, int(k ** 0.5 + 1)):
        if k % i == 0:
            div.append(i)
            if i * i != k:
                div.append(k // i)
    cnt = {}
    for b in B:
        g = gcd(b, k)
        for d in div:
            if g % d == 0:
                cnt[d] = cnt.get(d, 0) + 1
    ans = 0
    for a in A:
        g = gcd(a, k)
        ans += cnt.get(k // g, 0)
    print(ans)

    
0