結果

問題 No.854 公平なりんご分配
ユーザー rlangevin
提出日時 2023-10-23 21:37:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,074 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 286,168 KB
最終ジャッジ日時 2024-09-22 15:05:40
合計ジャッジ時間 27,096 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 50 TLE * 1 -- * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from math import *

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False
    for i in range(2, n + 1):
        if lst[i]:
            S.add(i)
    return sorted(list(S))

N = int(input())
A = list(map(int, input().split()))
Prime = Sieve(3000)
M = len(Prime)
D = [[0] * N for _ in range(M)]
Dc = [[0] * (N + 1) for _ in range(M)]
for i in range(M):
    for j in range(N):
        while A[j] % Prime[i] == 0:
            A[j] //= Prime[i]
            D[i][j] += 1
              
    for j in range(N):
        Dc[i][j + 1] = Dc[i][j] + D[i][j]
        
Q = int(input())
for _ in range(Q):
    P, L, R = map(int, input().split())
    L -= 1
    for i in range(M):
        cnt = 0
        while P % Prime[i] == 0:
            cnt += 1
            P //= Prime[i]
        if cnt > Dc[i][R] - Dc[i][L]:
            print("NO")
            break
    else:
        print("Yes") if P == 1 else print("NO")
0