結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-04-16 10:50:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 812 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 87,148 KB
実行使用メモリ 99,292 KB
最終ジャッジ日時 2023-08-26 16:41:29
合計ジャッジ時間 5,296 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,440 KB
testcase_01 AC 61 ms
71,688 KB
testcase_02 AC 64 ms
71,692 KB
testcase_03 AC 62 ms
71,592 KB
testcase_04 AC 69 ms
76,200 KB
testcase_05 AC 67 ms
71,316 KB
testcase_06 AC 63 ms
71,692 KB
testcase_07 AC 64 ms
71,936 KB
testcase_08 AC 64 ms
71,728 KB
testcase_09 AC 65 ms
71,488 KB
testcase_10 AC 115 ms
86,532 KB
testcase_11 AC 133 ms
90,104 KB
testcase_12 AC 318 ms
92,644 KB
testcase_13 AC 115 ms
86,292 KB
testcase_14 AC 126 ms
86,944 KB
testcase_15 AC 115 ms
81,004 KB
testcase_16 AC 128 ms
85,936 KB
testcase_17 AC 111 ms
80,900 KB
testcase_18 AC 324 ms
92,640 KB
testcase_19 AC 280 ms
84,996 KB
testcase_20 AC 158 ms
99,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
n,m,k = map(int,input().split())
L = list(input().split())
op = L[0]
B = [int(b) for b in L[1:]]
A = [int(input()) for i in range(n)] 

if op == "+":
    dic = {}
    for b in B:
        dic[b%k] = dic.get(b%k,0)+1

    ans = 0
    for a in A:
        ans += dic.get((k-a)%k,0)
    
else:
    dicB = {}

    for b in B:
        g = math.gcd(b,k)
        dicB[g] = dicB.get(g,0)+1

    dicA = {}

    for a in A:
        g = math.gcd(a,k)
        dicA[g] = dicA.get(g,0)+1

    divs = set()
    for i in range(1,int(k**0.5)+1):
        if k%i:
            continue
        divs.add(i)
        divs.add(k//i)

    ans = 0
    for i in divs:
        for j in divs:
            x = i*j
            if math.gcd(x,k) != k:
                continue
            ans += dicA.get(i,0)*dicB.get(j,0)
print(ans)
0