結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー freecss00
提出日時 2020-02-14 23:22:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 519 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 60,144 KB
最終ジャッジ日時 2024-11-16 01:39:40
合計ジャッジ時間 18,120 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 11 WA * 3 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import Counter

def getprimes(x):
    res = []
    a = 2
    while x > a*a:
        while x % a == 0:
            res.append(a)
            x //= a
        a += 1
    if x != 1:
        res.append(x)
    return res

def getfactors(x):
    res = []
    for i in range(1, int(x**0.5)+1):
        if x % i == 0:
            res.append(i)
            if i != x // i:
                res.append(x//i)
    res.sort()
    return res

n, m, k = map(int, input().split())
line = input().split()
op = line[0]
B = list(map(int, line[1:]))
A = [int(input()) for _ in range(n)]

if op == '+':
    mod = [a % k for a in A]
    modcnt = Counter(mod)
    ans = sum([modcnt[(k - (b%k)) % k] for b in B])
else:
    factors = []
    for a in A:
        factors += getfactors(a)
    factorcnt = Counter(factors)
    ans = 0
    for a in A:
        l = k // math.gcd(a, k)
        ans += factorcnt[l]
print(ans)
0