/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 73ms 27.777 MiB
#2 Accepted 80ms 29.93 MiB
#3 Accepted 288ms 69.469 MiB
#4 Accepted 292ms 69.516 MiB
#5 Accepted 220ms 70.094 MiB
#6 Accepted 235ms 70.531 MiB
#7 Accepted 259ms 71.297 MiB
#8 Accepted 253ms 71.332 MiB
#9 Accepted 240ms 71.23 MiB
#10 Accepted 279ms 71.883 MiB
#11 Accepted 245ms 71.934 MiB
#12 Accepted 270ms 72.02 MiB
#13 Accepted 253ms 71.289 MiB
#14 Accepted 264ms 70.504 MiB
#15 Accepted 367ms 69.941 MiB
#16 Accepted 353ms 69.902 MiB
#17 Accepted 232ms 69.809 MiB
#18 Accepted 333ms 68.574 MiB
#19 Accepted 230ms 69.184 MiB
#20 Accepted 238ms 70.062 MiB
#21 Accepted 294ms 71.027 MiB
#22 Accepted 293ms 70.621 MiB
#23 Accepted 329ms 70.648 MiB
#24 Accepted 319ms 73.941 MiB
#25 Accepted 209ms 70.645 MiB
#26 Accepted 273ms 68.727 MiB
#27 Accepted 321ms 95.277 MiB

Code

import sys
import math
from collections import defaultdict

MOD = 1000000007
LIMIT = 10**9

def prime():
    primes = [2]
    for i in range(3, int(math.sqrt(LIMIT)) + 1, 2):
        is_prime = True
        for p in primes:
            if p * p > i:
                break
            if i % p == 0:
                is_prime = False
                break
        if is_prime:
            primes.append(i)
    return primes

def main():
    input = sys.stdin.read
    data = input().split()
    
    index = 0
    t = int(data[index])
    index += 1
    primes = prime()
    
    results = []
    
    for _ in range(t):
        n = int(data[index])
        x = int(data[index + 1])
        index += 2
        
        mp = defaultdict(int)
        
        # Factor x
        for p in primes:
            if x < p:
                break
            while x % p == 0:
                mp[p] += 1
                x //= p
        if x > 1:
            mp[x] += 1
        
        compress = {}
        num = 1
        for key in mp:
            compress[key] = num
            num += 1
        
        dp = [[0] * (num + 1) for _ in range(n + 1)]
        
        for i in range(1, n + 1):
            a = int(data[index])
            index += 1
            
            for key in mp:
                cur = compress[key]
                while a % key == 0:
                    dp[i][cur] += 1
                    a //= key
            
            for pp in range(1, num):
                dp[i][pp] += dp[i - 1][pp]
        
        total = [0] * (num + 1)
        for key in mp:
            cur = compress[key]
            total[cur] = mp[key]
        
        q = int(data[index])
        index += 1
        
        for _ in range(q):
            l = int(data[index]) - 1
            r = int(data[index + 1])
            index += 2
            
            possible = True
            for pp in range(1, num):
                if dp[r][pp] - dp[l][pp] < total[pp]:
                    possible = False
                    break
            
            results.append("Yes" if possible else "No")
    
    print("\n".join(results))

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
PyPy 3 (Python 3.9.18 PyPy 7.3.15)
Submit At
2024-10-30 21:24:07
Judged At
2024-12-17 11:26:10
Judged By
Score
100
Total Time
367ms
Peak Memory
95.277 MiB