結果

問題 No.2211 Frequency Table of GCD
ユーザー ygd.ygd.
提出日時 2023-02-10 22:35:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,463 ms / 2,000 ms
コード長 1,715 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 129,904 KB
最終ジャッジ日時 2024-07-07 18:08:33
合計ジャッジ時間 13,604 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #
#sys.setrecursionlimit(1000000)
import math
import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
from collections import defaultdict
from collections import deque
import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
dx = [1,0,-1,0]
dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]
def make_divisors(n):
lower_divisors , upper_divisors = [], []
i = 1
while i*i <= n:
if n % i == 0:
lower_divisors.append(i)
if i != n // i:
upper_divisors.append(n//i)
i += 1
return lower_divisors + upper_divisors[::-1]
def main():
N,M = map(int,input().split()); MAX = 3*pow(10,5)
pow2 = [1]
for i in range(MAX):
pow2.append(pow2[-1]*2%MOD)
A = list(map(int,input().split()))
Adic = defaultdict(int)
for a in A:
Adic[a] += 1
dic = defaultdict(int)
for a,n in Adic.items():
X = make_divisors(a)
for x in X:
dic[x] += n
# print(dic)
ans = [0]*(M+1)
for i in reversed(range(1,M+1)):
temp = pow2[dic[i]] - 1
# print(i,temp)
if temp == 0:
ans[i] = temp
else:
for fac in range(2,MAX):
if i*fac > M: break
# print("XX",i*fac,ans[i*fac])
temp -= ans[i*fac]
temp %= MOD
ans[i] = temp
for i in range(1,M+1):
print(ans[i]%MOD)
if __name__ == '__main__':
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0