結果

問題 No.854 公平なりんご分配
ユーザー aaaaaaaaaa2230
提出日時 2022-05-20 12:58:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 896 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 156,672 KB
最終ジャッジ日時 2024-09-19 20:44:00
合計ジャッジ時間 15,912 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int,input().split()))
q = int(input())
P = []
LR = []
for i in range(q):
    p,l,r = map(int,input().split())
    P.append(p)
    LR.append([l-1,r])

M = 2*10**3+5
count = [0]*M
primes = []
for i in range(2,M):
    if count[i]:
        continue
    primes.append(i)
    for j in range(i,M,i):
        count[j] += 1

accum = [[0]*(len(primes)) for i in range(n+1)]
zero = [0]*(n+1)
for i,a in enumerate(A,1):
    zero[i] = zero[i-1]+int(a==0)
    for j,p in enumerate(primes):
        accum[i][j] = accum[i-1][j]
        while a%p == 0:
            a //= p
            accum[i][j] += 1

for p,(l,r) in zip(P,LR):
    if zero[r]-zero[l]:
        print("Yes")
        continue

    for j,d in enumerate(primes):
        
        num = accum[r][j]-accum[l][j]

        while num and p%d == 0:
            p //= d
            num -= 1
    print("Yes" if p == 1 else "NO")
0