11958 | 2024-11-22 12:04:26 | lacito | Villámosztás | pypy3 | Accepted 100/100 | 79ms | 21996 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())
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 46ms | 19700 KiB | ||||
subtask2 | 30/30 | ||||||
2 | Accepted | 46ms | 19508 KiB | ||||
3 | Accepted | 48ms | 19772 KiB | ||||
4 | Accepted | 52ms | 21476 KiB | ||||
5 | Accepted | 64ms | 21528 KiB | ||||
6 | Accepted | 68ms | 21480 KiB | ||||
subtask3 | 70/70 | ||||||
7 | Accepted | 46ms | 19508 KiB | ||||
8 | Accepted | 48ms | 19772 KiB | ||||
9 | Accepted | 52ms | 21476 KiB | ||||
10 | Accepted | 64ms | 21528 KiB | ||||
11 | Accepted | 68ms | 21480 KiB | ||||
12 | Accepted | 74ms | 21772 KiB | ||||
13 | Accepted | 70ms | 21920 KiB | ||||
14 | Accepted | 68ms | 21772 KiB | ||||
15 | Accepted | 71ms | 21972 KiB | ||||
16 | Accepted | 72ms | 21728 KiB | ||||
17 | Accepted | 79ms | 21996 KiB |