結果
問題 | No.2183 LCA on Rational Tree |
ユーザー |
![]() |
提出日時 | 2023-01-07 20:08:44 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 814 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 80,792 KB |
最終ジャッジ日時 | 2024-05-08 21:14:52 |
合計ジャッジ時間 | 8,427 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
58,112 KB |
testcase_01 | AC | 1,619 ms
80,792 KB |
testcase_02 | TLE | - |
testcase_03 | AC | 1,073 ms
77,952 KB |
testcase_04 | AC | 351 ms
77,464 KB |
testcase_05 | AC | 1,682 ms
78,428 KB |
ソースコード
from math import gcd def plist(m): pf = [] for i in range(2,int(m**0.5)+1): while m%i == 0: pf.append(i) m //= i if m>1 : pf.append(m) return pf def gogo(p:int, q:int, lst:list): pl = plist(q-p) while q-p > 1: x = 10 ** 18 for i in pl: if (q-p)%i == 0: x = min(x, i-(p%i)) g = gcd(p+x, q+x) lst.append((q-p, p, p+x)) p, q = (p+x)//g, (q+x)//g lst.append((1, p, 9 * 10 ** 18)) Q = int(input()) for _ in range(Q): lst1 = [] lst2 = [] p1,q1,p2,q2 = map(int,input().split()) gogo(p1,q1,lst1) gogo(p2,q2,lst2) g = dict() for i, st, ed in lst1: g[i] = (st, ed) ans1 = 0 ans2 = 0 #print(g) for i, st, ed in lst2: if i in g.keys(): v = max(0, min(ed, g[i][1]) - max(st, g[i][0])) if v > 0: ans1 = max(st, g[i][0]) ans2 = i + ans1 break print(ans1, ans2)