結果
| 問題 | No.2183 LCA on Rational Tree |
| ユーザー |
vwxyz
|
| 提出日時 | 2024-06-02 04:35:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 922 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 78,208 KB |
| 最終ジャッジ日時 | 2024-12-22 21:54:22 |
| 合計ジャッジ時間 | 9,078 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 5 TLE * 1 |
ソースコード
import math
from collections import defaultdict
def Divisors(N):
divisors=[]
for i in range(1,N+1):
if i**2>=N:
break
elif N%i==0:
divisors.append(i)
if i**2==N:
divisors+=[i]+[N//i for i in divisors[::-1]]
else:
divisors+=[N//i for i in divisors[::-1]]
return divisors
Q=int(input())
for q in range(Q):
a,b,c,d=map(int,input().split())
M=10**18
def tree(p,q):
D=Divisors(q-p)
def f(p,q):
if q-p==1:
return [(1,p,M)]
lst=[]
for d in D[1:]:
if (q-p)%d==0:
lst.append((-p)%d)
mi=min(lst)
pp=p+mi
qq=q+mi
g=math.gcd(pp,qq)
return [(q-p,p,pp)]+f(pp//g,qq//g)
return f(p,q)
tree0=tree(a,b)
tree1=tree(c,d)
assert len(tree0)<=30
assert len(tree1)<=30
vwxyz