結果

問題 No.854 公平なりんご分配
ユーザー H3PO4H3PO4
提出日時 2021-02-27 10:25:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,669 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 330,232 KB
最終ジャッジ日時 2024-04-10 15:19:42
合計ジャッジ時間 24,199 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
59,848 KB
testcase_01 AC 38 ms
61,264 KB
testcase_02 AC 36 ms
58,984 KB
testcase_03 AC 37 ms
60,768 KB
testcase_04 AC 35 ms
58,848 KB
testcase_05 AC 39 ms
60,124 KB
testcase_06 AC 39 ms
60,420 KB
testcase_07 AC 41 ms
60,892 KB
testcase_08 AC 41 ms
60,692 KB
testcase_09 AC 41 ms
61,044 KB
testcase_10 AC 39 ms
61,356 KB
testcase_11 AC 40 ms
60,756 KB
testcase_12 AC 43 ms
63,612 KB
testcase_13 AC 44 ms
63,632 KB
testcase_14 AC 37 ms
60,352 KB
testcase_15 AC 38 ms
60,700 KB
testcase_16 AC 42 ms
63,600 KB
testcase_17 AC 45 ms
63,628 KB
testcase_18 AC 38 ms
61,876 KB
testcase_19 AC 40 ms
61,944 KB
testcase_20 AC 39 ms
61,184 KB
testcase_21 AC 39 ms
61,592 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 MLE -
testcase_83 MLE -
testcase_84 MLE -
testcase_85 MLE -
testcase_86 MLE -
testcase_87 MLE -
testcase_88 MLE -
testcase_89 MLE -
testcase_90 MLE -
testcase_91 MLE -
testcase_92 MLE -
testcase_93 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# input = sys.stdin.buffer.readline


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return (i for i in range(n + 1) if is_prime[i])


def factorization(n):
    arr = dict()
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if not arr and n != 1:
        arr[n] = 1

    return arr


N = int(input())
A = tuple(map(int, input().split()))
Q = int(input())
queries = [tuple(map(int, input().split())) for _ in range(Q)]

P = tuple(primes(2000))
acc_list = [[0] * (N + 1) for _ in range(len(P))]
p2i = {pr: i for i, pr in enumerate(P)}
INF = 100
for i, a in enumerate(A, 1):
    if a:
        for k, v in factorization(a).items():
            acc_list[p2i[k]][i] += v
    else:
        for p in range(len(P)):
            acc_list[p][i] = INF
for p in range(len(P)):
    for i in range(N):
        acc_list[p][i + 1] += acc_list[p][i]

for p, l, r in queries:
    temp = p
    for pr in P:
        ct = 0
        while not temp % pr:
            temp //= pr
            ct += 1
        diff = acc_list[p2i[pr]][r] - acc_list[p2i[pr]][l - 1]
        if diff >= INF:
            print('Yes')
            break
        elif diff < ct:
            print('NO')
            break
    else:
        print('Yes' if temp == 1 else 'NO')
0