結果

問題 No.2081 Make a Test Case of GCD Subset
ユーザー taiga0629kyoprotaiga0629kyopro
提出日時 2022-09-07 14:43:04
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,583 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 72,564 KB
最終ジャッジ日時 2024-05-03 11:12:59
合計ジャッジ時間 5,532 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,680 KB
testcase_01 AC 64 ms
71,936 KB
testcase_02 AC 63 ms
72,064 KB
testcase_03 AC 62 ms
71,808 KB
testcase_04 AC 63 ms
71,808 KB
testcase_05 AC 61 ms
71,808 KB
testcase_06 AC 62 ms
72,064 KB
testcase_07 AC 63 ms
71,936 KB
testcase_08 AC 63 ms
72,448 KB
testcase_09 AC 64 ms
71,808 KB
testcase_10 AC 64 ms
72,192 KB
testcase_11 AC 63 ms
71,808 KB
testcase_12 AC 63 ms
71,808 KB
testcase_13 AC 64 ms
71,936 KB
testcase_14 AC 64 ms
72,320 KB
testcase_15 AC 62 ms
71,936 KB
testcase_16 AC 63 ms
72,064 KB
testcase_17 AC 62 ms
71,808 KB
testcase_18 AC 62 ms
71,680 KB
testcase_19 AC 63 ms
71,808 KB
testcase_20 AC 62 ms
71,936 KB
testcase_21 AC 62 ms
71,424 KB
testcase_22 AC 63 ms
71,680 KB
testcase_23 WA -
testcase_24 AC 69 ms
71,808 KB
testcase_25 AC 64 ms
71,424 KB
testcase_26 AC 66 ms
71,808 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #


class primes():
    def __init__(self, n):
        self.prime_num = n
        self.min_prime = [-1] * (self.prime_num + 1)  # 2以上の自然数に対して最小の素因数を表す
        self.min_prime[0] = 0
        self.min_prime[1] = 1
        i = 2
        self.prime = []
        self.memo_prifac = {}
        while i <= self.prime_num:
            if self.min_prime[i] == -1:
                self.min_prime[i] = i
                self.prime.append(i)
            for j in self.prime:
                if i * j > self.prime_num or j > self.min_prime[i]: break
                self.min_prime[j * i] = j
            i += 1

    def prifac(self, n):
        # 素因数分解した結果を返す
        if n in self.memo_prifac:
            return self.memo_prifac[n]
        res = {}
        x = n
        while x > 1:
            p = self.min_prime[x]
            if p in res:
                res[p] += 1
            else:
                res[p] = 1
            x //= p

        # self.memo_prifac[n] = res  #場合によってはこの行を消すと高速化

        return res

    def divisors(self, n):
        # 約数列挙 メモした方がいいかも
        if n== 1: return [1]
        prf = self.prifac(n)
        keys = [key for key in prf]

        def divsearch(i):
            if i == len(keys) - 1:
                return [keys[i] ** j for j in range(prf[keys[i]] + 1)]
            else:
                res = []
                subres = divsearch(i + 1)
                p = keys[i]
                for j in range(prf[p] + 1):
                    for node in subres:
                        res.append(node * p ** j)
                return res

        return divsearch(0)

pri=primes(10**5+10)
def sol(n,a):
    mod=998244353
    dp=[0]*(10**5+1)
    ans=0
    for x in a:
        for y in pri.divisors(x):dp[y]+=1
    for x in range(10**5,1,-1):
        dp[x]=pow(2,dp[x],mod)-1
        for y in range(2*x,10**5+1,x):
            dp[x]-=dp[y]
        dp[x]%=mod
        ans+=dp[x]
    return ans%mod
def make(m):
    if m==0:
        return 1,[1]
    p=pri.prime
    ind=0

    a=[]
    for i in range(29,-1,-1):
        if m-2**i>=0:
            for _ in range(i):
                a.append(p[ind])
            ind+=1
            a.append(p[ind])
            ind+=1
            m-=2**i
    n=len(a)
    for i in range(n-1,-1,-1):
        if a.count(a[i])>=2:
            a[i]*=p[ind]
            ind+=1
    return n,a

#check
m=int(input())
if not (0<=m<998244353):print(aaa)
n,a=make(m)
from random import shuffle
print(n)
shuffle(a)
print(*a)



0