結果

問題 No.990 N×Mマス計算(Kの倍数)
コンテスト
ユーザー ntuda
提出日時 2025-01-25 09:34:59
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 916 ms / 2,000 ms
コード長 874 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 873 ms
コンパイル使用メモリ 85,148 KB
実行使用メモリ 103,712 KB
最終ジャッジ日時 2026-06-23 13:55:18
合計ジャッジ時間 5,534 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import defaultdict
from math import gcd

def make_divisors(n):
    divisors = []  #必要に応じてsetにしても良いかも
    i = 1
    while i ** 2 <= n:
        if n % i == 0:
            divisors.append(i)
            if i ** 2 != n:
                divisors.append(n//i)
        i += 1
    divisors.sort()
    return divisors

dic = defaultdict(int)
N, M, K = map(int, input().split())
op, *B = input().split()
A = []
for i in range(N):
    A.append(int(input()))
B = [int(i) for i in B]
ans = 0
if op == "+":
    for b in B:
        dic[(-b) % K] += 1
    for a in A:
        if a % K in dic:
            ans += dic[a % K]
else:
    D = make_divisors(K)
    for b in B:
        for d in D:
            if b % d == 0:
                dic[d] += 1
    for a in A:
        x = K // gcd(a,K)
        if x in dic:
            ans += dic[x]
print(ans)
0