結果
問題 | No.2578 Jewelry Store |
ユーザー | suisen |
提出日時 | 2023-01-11 17:30:10 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,088 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 78,376 KB |
最終ジャッジ日時 | 2024-09-27 00:31:15 |
合計ジャッジ時間 | 6,180 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
ソースコード
import sys from typing import List input = sys.stdin.readline #BEGIN: https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98 def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def isPrimeMR(n: int): d = n - 1 d = d // (d & -d) L = [2] for a in L: t = d y = pow(a, t, n) if y == 1: continue while y != n - 1: y = (y * y) % n if y == 1 or t == n - 1: return 0 t <<= 1 return 1 def findFactorRho(n: int): m = 1 << n.bit_length() // 8 for c in range(1, 99): f = lambda x: (x * x + c) % n y, r, q, g = 2, 1, 1, 1 while g == 1: x = y for i in range(r): y = f(y) k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = f(y) q = q * abs(x - y) % n g = gcd(q, n) k += m r <<= 1 if g == n: g = 1 while g == 1: ys = f(ys) g = gcd(abs(x - ys), n) if g < n: if isPrimeMR(g): return g elif isPrimeMR(n // g): return n // g return findFactorRho(g) def primeFactor(n): i = 2 ret = {} rhoFlg = 0 while i*i <= n: k = 0 while n % i == 0: n //= i k += 1 if k: ret[i] = k i += 1 + i % 2 if i == 101 and n >= 2 ** 20: while n > 1: if isPrimeMR(n): ret[n], n = 1, 1 else: rhoFlg = 1 j = findFactorRho(n) k = 0 while n % j == 0: n //= j k += 1 ret[j] = k if n > 1: ret[n] = 1 if rhoFlg: ret = {x: ret[x] for x in sorted(ret)} return ret #END: https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98 P = 998244353 t, m = map(int, input().split()) pf = primeFactor(m).keys() k = len(pf) for _ in range(t): n = int(input()) a = list(map(int, input().split())) w = list(map(int, input().split())) a2 = [] w2 = [] for i, (ai, wi) in enumerate(zip(a, w)): if m % ai == 0: a2.append(ai) w2.append(wi) a = a2 w = w2 zeta = [1] * (1 << k) for ai, wi in zip(a, w): t = 0 for j, p in enumerate(pf): if (m // p) % ai: t |= 1 << j zeta[t] = zeta[t] * ((1 + wi) % P) % P block = 1 while block < 1 << k: offset = 0 while offset < 1 << k: for i in range(offset, offset + block): zeta[i + block] = zeta[i + block] * zeta[i] % P offset += 2 * block block <<= 1 ans = 0 for s in range(1 << k): if (bin(s).count('1') & 1): ans -= zeta[s] else: ans += zeta[s] if m == 1: ans -= 1 print(ans % P, flush=False)