結果

問題 No.1250 汝は倍数なりや?
ユーザー wattaihei
提出日時 2020-10-09 21:38:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 239 ms / 1,000 ms
コード長 1,015 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 28,440 KB
最終ジャッジ日時 2024-07-20 09:51:38
合計ジャッジ時間 5,272 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

# 素因数分解、辞書で返すやつ
import math
# mathをimportする
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
        if num > n:
            break
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

import sys
input = sys.stdin.buffer.readline
N, H = map(int, input().split())
A = list(map(int, input().split()))

if 0 in A:
    D = {}
else:
    D = prime(H)
    for a in A:
        to_del = []
        for n in D.keys():
            r = 0
            while a % n == 0:
                a //= n
                r += 1
            if D[n] > r:
                D[n] -= r
            else:
                to_del.append(n)

        for d in to_del:
            del D[d]

print("YES" if not D else "NO")
0