結果

問題 No.2578 Jewelry Store
ユーザー chineristACchineristAC
提出日時 2023-12-06 00:50:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,322 bytes
コンパイル時間 489 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 158,764 KB
最終ジャッジ日時 2023-12-06 00:51:18
合計ジャッジ時間 23,682 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
65,328 KB
testcase_01 AC 67 ms
65,328 KB
testcase_02 AC 139 ms
78,392 KB
testcase_03 AC 127 ms
78,244 KB
testcase_04 AC 194 ms
78,392 KB
testcase_05 WA -
testcase_06 AC 138 ms
78,392 KB
testcase_07 AC 197 ms
78,264 KB
testcase_08 AC 124 ms
78,372 KB
testcase_09 AC 194 ms
78,524 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 125 ms
78,372 KB
testcase_13 AC 125 ms
78,372 KB
testcase_14 AC 134 ms
78,360 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 198 ms
78,528 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 190 ms
78,392 KB
testcase_21 AC 197 ms
78,396 KB
testcase_22 AC 124 ms
78,132 KB
testcase_23 AC 140 ms
77,888 KB
testcase_24 AC 107 ms
77,900 KB
testcase_25 AC 124 ms
77,908 KB
testcase_26 AC 121 ms
78,016 KB
testcase_27 AC 307 ms
78,652 KB
testcase_28 AC 562 ms
78,812 KB
testcase_29 AC 503 ms
78,676 KB
testcase_30 AC 694 ms
79,056 KB
testcase_31 AC 297 ms
78,524 KB
testcase_32 AC 264 ms
127,000 KB
testcase_33 AC 289 ms
107,516 KB
testcase_34 AC 350 ms
121,840 KB
testcase_35 AC 177 ms
93,692 KB
testcase_36 AC 309 ms
124,280 KB
testcase_37 AC 235 ms
78,380 KB
testcase_38 AC 268 ms
79,404 KB
testcase_39 AC 245 ms
83,868 KB
testcase_40 AC 241 ms
79,540 KB
testcase_41 AC 235 ms
78,500 KB
testcase_42 AC 233 ms
78,516 KB
testcase_43 AC 325 ms
78,788 KB
testcase_44 AC 192 ms
78,384 KB
testcase_45 AC 259 ms
78,516 KB
testcase_46 AC 224 ms
80,912 KB
testcase_47 AC 1,428 ms
79,564 KB
testcase_48 AC 475 ms
158,764 KB
testcase_49 AC 3,364 ms
110,044 KB
testcase_50 TLE -
testcase_51 AC 240 ms
79,004 KB
testcase_52 AC 559 ms
79,184 KB
testcase_53 AC 154 ms
78,336 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