結果

問題 No.2578 Jewelry Store
ユーザー chineristACchineristAC
提出日時 2023-12-06 00:50:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,322 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 159,152 KB
最終ジャッジ日時 2024-09-27 00:47:54
合計ジャッジ時間 24,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
64,768 KB
testcase_01 AC 70 ms
64,768 KB
testcase_02 AC 140 ms
78,720 KB
testcase_03 AC 129 ms
78,592 KB
testcase_04 AC 198 ms
78,720 KB
testcase_05 WA -
testcase_06 AC 140 ms
78,976 KB
testcase_07 AC 192 ms
78,592 KB
testcase_08 AC 130 ms
78,592 KB
testcase_09 AC 198 ms
78,720 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 132 ms
78,848 KB
testcase_13 AC 132 ms
78,976 KB
testcase_14 AC 128 ms
78,848 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 199 ms
79,232 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 195 ms
78,720 KB
testcase_21 AC 198 ms
78,848 KB
testcase_22 AC 131 ms
78,336 KB
testcase_23 AC 138 ms
78,720 KB
testcase_24 AC 111 ms
78,464 KB
testcase_25 AC 128 ms
78,464 KB
testcase_26 AC 125 ms
78,336 KB
testcase_27 AC 307 ms
79,232 KB
testcase_28 AC 548 ms
79,488 KB
testcase_29 AC 512 ms
78,848 KB
testcase_30 AC 670 ms
79,360 KB
testcase_31 AC 306 ms
78,848 KB
testcase_32 AC 273 ms
127,488 KB
testcase_33 AC 300 ms
108,092 KB
testcase_34 AC 357 ms
122,380 KB
testcase_35 AC 169 ms
93,824 KB
testcase_36 AC 317 ms
124,652 KB
testcase_37 AC 238 ms
78,976 KB
testcase_38 AC 256 ms
79,872 KB
testcase_39 AC 258 ms
84,224 KB
testcase_40 AC 268 ms
80,128 KB
testcase_41 AC 266 ms
78,976 KB
testcase_42 AC 268 ms
78,848 KB
testcase_43 AC 310 ms
79,488 KB
testcase_44 AC 201 ms
78,848 KB
testcase_45 AC 262 ms
78,976 KB
testcase_46 AC 233 ms
81,140 KB
testcase_47 AC 1,406 ms
79,872 KB
testcase_48 AC 474 ms
159,152 KB
testcase_49 AC 3,262 ms
110,336 KB
testcase_50 AC 3,483 ms
114,032 KB
testcase_51 AC 242 ms
79,488 KB
testcase_52 AC 567 ms
79,488 KB
testcase_53 AC 156 ms
78,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def isPrimeMR(n):
    if n==1:
        return 0
    d = n - 1
    d = d // (d & -d)
    L = [2, 3, 5, 7, 11, 13, 17]
    if n in L:
        return 1
    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):
    from math import gcd
    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

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

K = 17
popcount = [0] * (1<<K)
for i in range(K):
    for S in range(1<<K):
        if S >> i & 1:
            popcount[S] ^= 1

mod = 998244353

T,M = mi()

pf = primeFactor(M)
"""
M_div = [1]
for p in pf:
    e = pf[p]
    nxt_M_div = []
    for a in M_div:
        t = 1
        for i in range(e+1):
            nxt_M_div.append(a * t)
            t *= p
    M_div = nxt_M_div

M_div.sort()
"""


M_prime = [pow(p,pf[p]) for p in pf]
M_n = len(M_prime)

def solve1(N,B,C,D,A):
    dic = {}
    w = B
    for a in A:
        if M % a:
            w = (C * w + D) % mod
            continue
        if a not in dic:
            dic[a] = 1
        dic[a] *= w + 1
        dic[a] %= mod

        w = (C * w + D) % mod
    
    for p in pf:
        for d in M_div:
            if d not in dic:
                continue
            if M % (d*p):
                continue
            if d*p not in dic:
                dic[d*p] = 1
            dic[d*p] *= dic[d]
            dic[d*p] %= mod
        
    
    for d in dic:
        dic[d] = (dic[d] - 1 ) % mod
    
    for p in pf:
        for d in M_div[::-1]:
            if d % p:
                continue
            if d // p not in dic:
                continue
            dic[d] -= dic[d//p]
            dic[d] %= mod
    
    
    if M not in dic:
        return 0
    return dic[M]


def solve2(N,B,C,D,A):
    dp = [1] * (1<<M_n)
    w = B
    for a in A:
        if M % a:
            w = (C * w + D) % mod
            continue

        S = 0
        for i in range(M_n):
            if a % M_prime[i] == 0:
                S ^= 1<<i
        dp[S] *= 1 + w
        dp[S] %= mod

        w = (C * w + D) % mod
    
    for i in range(M_n):
        dp[2**i] *= -1
        dp[2**i] %= mod
    
    
    
    for i in range(M_n):
        t = 1<<i
        for S in range(1<<M_n):
            if S>>i & 1 == 0:
                dp[S^t] *= dp[S]
                dp[S^t] %= mod
    
    
    res = sum(dp) % mod
    if M_n & 1:
        res = mod-res % mod
    return res

    

for _ in range(T):
    N,B,C,D = mi()
    A = li()
    if M!=1:
        print(solve2(N,B,C,D,A))
    else:
        print((solve2(N,B,C,D,A)-1) % mod)
    #print(solve1(N,B,C,D,A))

0