/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 14ms 3.02 MiB
#2 Wrong Answer 19ms 3.02 MiB
#3 Wrong Answer 453ms 3.184 MiB

Code

from math import sqrt

knownPrimes = []

def getPrimeFactorization(n):
    fac = []

    hasDistinctPrimeFactor = False
    for p in knownPrimes:
        exp = 0
        while n % p == 0:
            exp += 1
            n //= p
        if exp > 0:
            hasDistinctPrimeFactor = True
            fac.append([p, exp])
        if n == 1:
            break
    
    squareRootN = int(sqrt(n))
    MIN = max(2, knownPrimes[-1] if knownPrimes else 0)
    for i in range(2, n + 1):
        if i > squareRootN + 1 and not hasDistinctPrimeFactor:
            break
        exp = 0
        while n % i == 0:
            if not knownPrimes or knownPrimes[-1] != i:
                knownPrimes.append(i)
            exp += 1
            n //= i
        if exp > 0:
            hasDistinctPrimeFactor = True
            fac.append([i, exp])
        if n == 1:
            break
    if n != 1:
        fac.append([n, 1])

    return fac

def numFromFactorization(fac):
    res = 1
    for p, exp in fac:
        if exp == 0:
            break
        res *= p**exp

    return res

def game(x, k):
    fac = getPrimeFactorization(x)
    # print(x)
    # print(fac)
    royMoves = (k + 1) // 2
    hridoyMoves = k - royMoves
    # print(royMoves, hridoyMoves)
    fac[0][1] += royMoves
    for i in range(len(fac) - 1, -1, -1):
        if fac[i][1] < hridoyMoves:
            hridoyMoves -= fac[i][1]
            fac[i][1] = 0
            continue
        fac[i][1] -= hridoyMoves
        break
    return numFromFactorization(fac)

t = int(input())
for _ in range(t):
    x, k = [int(c) for c in input().split(' ')]
    print(game(x, k))

Information

Submit By
Type
Submission
Problem
P1194 D. Roy and Prime Game
Contest
Happy New Year 2026
Language
Python 3 (Python 3.12.3)
Submit At
2026-01-06 17:12:57
Judged At
2026-01-06 17:12:57
Judged By
Score
0
Total Time
453ms
Peak Memory
3.184 MiB