結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー freecss00freecss00
提出日時 2020-02-14 23:22:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 919 bytes
コンパイル時間 102 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 30,444 KB
最終ジャッジ日時 2024-04-27 20:19:00
合計ジャッジ時間 4,257 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
17,820 KB
testcase_01 AC 24 ms
10,880 KB
testcase_02 WA -
testcase_03 AC 25 ms
10,880 KB
testcase_04 AC 33 ms
10,880 KB
testcase_05 AC 24 ms
10,880 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 24 ms
10,880 KB
testcase_09 AC 24 ms
10,880 KB
testcase_10 AC 130 ms
19,368 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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