結果

問題 No.990 N×Mマス計算(Kの倍数)
ユーザー nehan_der_thalnehan_der_thal
提出日時 2020-02-27 21:15:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,475 bytes
コンパイル時間 230 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 148,200 KB
最終ジャッジ日時 2024-04-27 21:35:34
合計ジャッジ時間 4,505 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
61,364 KB
testcase_01 AC 40 ms
55,004 KB
testcase_02 AC 48 ms
63,728 KB
testcase_03 AC 40 ms
54,188 KB
testcase_04 AC 47 ms
61,460 KB
testcase_05 AC 41 ms
54,780 KB
testcase_06 AC 53 ms
62,816 KB
testcase_07 AC 46 ms
62,060 KB
testcase_08 AC 35 ms
55,892 KB
testcase_09 AC 37 ms
55,064 KB
testcase_10 AC 101 ms
90,316 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
def prime_decomposition(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        c = 0
        while n % i == 0:
            n /= i
            c+=1
        if c!=0:
            table[i] = c
        i += 1
    if n > 1:
        table[int(n)] = 1
    return table
N, M, K = map(int, input().split())
R = 0
table = prime_decomposition(K)
bs = []
fs = []
bbs = dict()
ffs = dict()
for i in range(N+1):
    if i == 0:
        X = input().split()
        e = X[0] == '+'
        if e:
            d = defaultdict(int)
            for x in X[1:]:
                d[K-int(x)%K] += 1
        else:
            bs = list(map(lambda x: prime_decomposition(int(x)), X[1:]))
            d = defaultdict(int)
            for b in bs:
                d[1] += 1
                yakusus = [1]
                for k in b:
                    yn = len(yakusus)
                    for j in range(yn):
                        for l in range(b[k]):
                            yakusus.append(yakusus[j]*(k**(l+1)))
                            d[yakusus[j]*(k**(l+1))] += 1
        continue
    x = int(input())
    if e:
        R += d[x%K]
    else:
        fs.append(prime_decomposition(x))
if e:
    print(R)
else:
    R = 0
    for b in fs:
        r = K
        for key in b:
            if key in table:
                r //= key**min(table[key], b[key])
#        print(r, K)
        R += d[r]
    #        ffs[key].sort()

    print(R)
0