結果

問題 No.1250 汝は倍数なりや?
ユーザー ryhohryhoh
提出日時 2020-11-16 21:23:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 1,814 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 13,264 KB
最終ジャッジ日時 2023-09-30 07:30:08
合計ジャッジ時間 4,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
13,264 KB
testcase_01 AC 19 ms
8,820 KB
testcase_02 AC 22 ms
8,712 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from functools import reduce
from operator import add
import math


def make_primes(size: int) -> list:
    if not isinstance(size, int):
        raise AttributeError("args must be int but given %s" % size.__class__)
    if size < 0:
        raise ValueError("args must be (size < 0) but given %s" % size)
    if size < 2:
        return []

    res = []
    flag = [True for _ in range(size + 1)]
    limit = int(math.sqrt(size))

    for i in range(2, limit + 1):
        if flag[i]:
            res.append(i)
            for j in range(i, size + 1, i):
                flag[j] = False

    for i in range(max(2, limit), size + 1):
        if flag[i]:
            res.append(i)

    return res


def prime_factor(n: int, primes: list) -> Counter:
    if not isinstance(n, int) or not isinstance(primes, list):
        raise AttributeError("args must be int but given (%s, %s)" % (n.__class__, primes.__class__))
    if n < 1:
        raise ValueError("args must be (n < 1) but given %s" % n)

    res = Counter({1: 1})
    while True:
        ok = False
        for i in range(len(primes)):
            if n % primes[i] == 0:
                if primes[i] in res:
                    res[primes[i]] += 1
                else:
                    res[primes[i]] = 1
                n = n // primes[i]
                break
            if primes[i] > n:
                ok = True
                break
        if ok:
            break
    return res


if __name__ == '__main__':
    N, H = map(int, input().split())
    A = list(map(int, input().split()))

    primes = make_primes(H+1)
    A_factor = reduce(add, (prime_factor(a, primes) for a in A))
    h_factor = prime_factor(H, primes)

    if A_factor & h_factor == h_factor:
        print("YES")
    else:
        print("NO")
0