結果

問題 No.2183 LCA on Rational Tree
ユーザー tailstails
提出日時 2023-01-17 19:50:23
言語 cLay
(20240104-1)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 525 bytes
コンパイル時間 7,183 ms
コンパイル使用メモリ 221,920 KB
実行使用メモリ 10,584 KB
最終ジャッジ日時 2023-08-30 23:00:07
合計ジャッジ時間 7,674 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
10,500 KB
testcase_01 AC 31 ms
10,584 KB
testcase_02 AC 46 ms
10,500 KB
testcase_03 AC 26 ms
10,500 KB
testcase_04 AC 14 ms
10,484 KB
testcase_05 AC 31 ms
10,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

struct S{
	ull p,q,l,n,f[32];
	S(){
		rd(p,q);
		n=Factor(q-=p,f);
		l=0;
	}
	void step(){
		p+=l;
		rep[f](x,n){
			while(p%x==0&&q%x==0){
				p/=x;
				q/=x;
			}
		}
		l=1<<30;
		rep[f](x,n){
			if(q%x==0){
				l<?=x-p%x;
			}
		}
	}
};

bool h(S&u,S&v){
	if(u.p<=v.p<u.p+u.l){
		wt(v.p,v.p+v.q);
		return true;
	}
	return false;
}

{
	ll@q;
	rep(q){
		S u,v;
		while(1){
			ll d=v.q-u.q;
			if(d==0){
				if(h(u,v)||h(v,u)){
					break;
				}
			}
			if(d<=0){
				u.step();
			}
			if(d>=0){
				v.step();
			}
		}
	}
}
0