119582024-11-22 12:04:26lacitoVillámosztáspypy3Accepted 100/10079ms21996 KiB
#!/usr/bin/env python3
# @check-accepted: *

from itertools import product

def primeFactor(n):
    res=[]
    i=2
    while i*i<=n:
        cur=0
        while n%i==0:
            cur+=1
            n//=i
        if cur!=0:
            res.append((i,cur))
        i+=1
    if n>1:
        res+=[(n,1)]
    return res

def sol():
    a,b,k = map(int, input().strip().split())
    primes=primeFactor(a+b+k)
    res=1
    for A in product(*[range(n+1) for p,n in primes]):
        cur=1
        for i in range(len(primes)):
            cur*=primes[i][0]**A[i]
        if cur>res:
            i=a//cur
            if a <= cur*i <= a+k or a <= cur*(i+1) <= a+k:
                res=cur
    return res 

for t in range(int(input())):
    print(sol())
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted46ms19700 KiB
subtask230/30
2Accepted46ms19508 KiB
3Accepted48ms19772 KiB
4Accepted52ms21476 KiB
5Accepted64ms21528 KiB
6Accepted68ms21480 KiB
subtask370/70
7Accepted46ms19508 KiB
8Accepted48ms19772 KiB
9Accepted52ms21476 KiB
10Accepted64ms21528 KiB
11Accepted68ms21480 KiB
12Accepted74ms21772 KiB
13Accepted70ms21920 KiB
14Accepted68ms21772 KiB
15Accepted71ms21972 KiB
16Accepted72ms21728 KiB
17Accepted79ms21996 KiB