結果

問題 No.854 公平なりんご分配
ユーザー mkawa2mkawa2
提出日時 2021-02-26 01:52:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,270 ms / 3,153 ms
コード長 2,604 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 292,680 KB
最終ジャッジ日時 2024-04-09 18:09:25
合計ジャッジ時間 27,489 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,704 KB
testcase_01 AC 42 ms
55,052 KB
testcase_02 AC 40 ms
55,248 KB
testcase_03 AC 41 ms
54,924 KB
testcase_04 AC 42 ms
55,164 KB
testcase_05 AC 41 ms
55,304 KB
testcase_06 AC 40 ms
55,800 KB
testcase_07 AC 43 ms
55,024 KB
testcase_08 AC 42 ms
55,868 KB
testcase_09 AC 43 ms
55,448 KB
testcase_10 AC 41 ms
55,384 KB
testcase_11 AC 42 ms
55,948 KB
testcase_12 AC 47 ms
61,800 KB
testcase_13 AC 46 ms
61,660 KB
testcase_14 AC 43 ms
56,380 KB
testcase_15 AC 43 ms
54,708 KB
testcase_16 AC 46 ms
62,264 KB
testcase_17 AC 47 ms
61,928 KB
testcase_18 AC 46 ms
62,208 KB
testcase_19 AC 46 ms
62,232 KB
testcase_20 AC 43 ms
55,700 KB
testcase_21 AC 46 ms
62,760 KB
testcase_22 AC 65 ms
69,196 KB
testcase_23 AC 67 ms
71,584 KB
testcase_24 AC 88 ms
77,736 KB
testcase_25 AC 58 ms
67,800 KB
testcase_26 AC 89 ms
77,996 KB
testcase_27 AC 75 ms
75,260 KB
testcase_28 AC 63 ms
67,824 KB
testcase_29 AC 51 ms
63,876 KB
testcase_30 AC 62 ms
68,188 KB
testcase_31 AC 86 ms
77,268 KB
testcase_32 AC 253 ms
146,128 KB
testcase_33 AC 240 ms
93,248 KB
testcase_34 AC 375 ms
163,556 KB
testcase_35 AC 289 ms
146,840 KB
testcase_36 AC 194 ms
79,548 KB
testcase_37 AC 235 ms
130,288 KB
testcase_38 AC 189 ms
98,296 KB
testcase_39 AC 468 ms
166,288 KB
testcase_40 AC 265 ms
91,576 KB
testcase_41 AC 289 ms
129,644 KB
testcase_42 AC 328 ms
160,784 KB
testcase_43 AC 366 ms
138,088 KB
testcase_44 AC 396 ms
158,140 KB
testcase_45 AC 347 ms
84,584 KB
testcase_46 AC 467 ms
160,024 KB
testcase_47 AC 234 ms
96,808 KB
testcase_48 AC 324 ms
147,652 KB
testcase_49 AC 317 ms
153,004 KB
testcase_50 AC 216 ms
134,236 KB
testcase_51 AC 455 ms
153,968 KB
testcase_52 AC 279 ms
94,012 KB
testcase_53 AC 214 ms
93,820 KB
testcase_54 AC 285 ms
96,216 KB
testcase_55 AC 177 ms
93,540 KB
testcase_56 AC 178 ms
94,476 KB
testcase_57 AC 217 ms
91,112 KB
testcase_58 AC 290 ms
82,580 KB
testcase_59 AC 164 ms
89,976 KB
testcase_60 AC 247 ms
91,824 KB
testcase_61 AC 161 ms
80,292 KB
testcase_62 AC 276 ms
89,072 KB
testcase_63 AC 199 ms
89,812 KB
testcase_64 AC 154 ms
81,976 KB
testcase_65 AC 264 ms
158,404 KB
testcase_66 AC 208 ms
86,596 KB
testcase_67 AC 251 ms
99,108 KB
testcase_68 AC 236 ms
87,636 KB
testcase_69 AC 256 ms
153,796 KB
testcase_70 AC 170 ms
91,380 KB
testcase_71 AC 178 ms
92,200 KB
testcase_72 AC 222 ms
79,580 KB
testcase_73 AC 233 ms
142,864 KB
testcase_74 AC 316 ms
151,772 KB
testcase_75 AC 219 ms
92,500 KB
testcase_76 AC 247 ms
138,364 KB
testcase_77 AC 292 ms
160,024 KB
testcase_78 AC 302 ms
89,172 KB
testcase_79 AC 271 ms
100,180 KB
testcase_80 AC 274 ms
132,048 KB
testcase_81 AC 247 ms
134,256 KB
testcase_82 AC 561 ms
291,956 KB
testcase_83 AC 1,182 ms
292,680 KB
testcase_84 AC 1,168 ms
291,720 KB
testcase_85 AC 263 ms
90,972 KB
testcase_86 AC 108 ms
90,676 KB
testcase_87 AC 565 ms
292,084 KB
testcase_88 AC 557 ms
292,072 KB
testcase_89 AC 549 ms
292,296 KB
testcase_90 AC 518 ms
292,404 KB
testcase_91 AC 549 ms
291,872 KB
testcase_92 AC 1,270 ms
292,312 KB
testcase_93 AC 1,250 ms
292,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**6)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.buffer.readline())
def FI(): return float(sys.stdin.buffer.readline())
def MI(): return map(int, sys.stdin.buffer.readline().split())
def MF(): return map(float, sys.stdin.buffer.readline().split())
def MI1(): return map(int1, sys.stdin.buffer.readline().split())
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def BI(): return sys.stdin.buffer.readline().rstrip()
def SI(): return sys.stdin.buffer.readline().rstrip().decode()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
inf = 10**16
# md = 998244353
md = 10**9+7

class Sieve:
    def __init__(self, n):
        self.plist = [2]  # n以下の素数のリスト
        min_prime_factor = [2, 0]*(n//2+5)
        for x in range(3, n+1, 2):
            if min_prime_factor[x] == 0:
                min_prime_factor[x] = x
                self.plist.append(x)
                if x**2 > n: continue
                for y in range(x**2, n+5, 2*x):
                    if min_prime_factor[y] == 0:
                        min_prime_factor[y] = x
        self.min_prime_factor = min_prime_factor

    def isprime(self, x):
        return self.min_prime_factor[x] == x

    # これが素因数分解(prime factorization)
    def pfct(self, x):
        pp, ee = [], []
        while x > 1:
            mpf = self.min_prime_factor[x]
            if pp and mpf == pp[-1]:
                ee[-1] += 1
            else:
                pp.append(mpf)
                ee.append(1)
            x //= mpf
        return [(p, e) for p, e in zip(pp, ee)]

from collections import defaultdict
from array import array

sv = Sieve(2005)
n = II()
aa = LI()
df = lambda: array("I", [0]*(n+1))
cs = defaultdict(df)

for i, a in enumerate(aa):
    if a == 0:
        cs[0][i+1] = 1
    else:
        pe = sv.pfct(a)
        for p, e in pe: cs[p][i+1] = e

for k, v in cs.items():
    for i in range(n): v[i+1] += v[i]
# print(cs)

def ok(a):
    if a == 1: return True
    if cs[0][r]-cs[0][l]: return True
    for p in cs.keys():
        if p == 0: continue
        e = 0
        while a%p == 0:
            a //= p
            e += 1
        if e and cs[p][r]-cs[p][l] < e: return False
    if a != 1: return False
    return True

for _ in range(II()):
    a, l, r = MI()
    l -= 1
    print("Yes" if ok(a) else "NO")
0