結果

問題 No.2183 LCA on Rational Tree
ユーザー tailstails
提出日時 2023-01-17 20:13:41
言語 cLay
(20240104-1)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 3,116 ms
コンパイル使用メモリ 183,912 KB
実行使用メモリ 7,512 KB
最終ジャッジ日時 2024-06-10 22:39:36
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 63 ms
6,940 KB
testcase_02 AC 61 ms
6,944 KB
testcase_03 AC 64 ms
6,940 KB
testcase_04 AC 20 ms
7,512 KB
testcase_05 AC 66 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

unsigned primes[3500];
ll nprimes;

ll factors(unsigned v,unsigned*a){
	ll n=0;
	rep[primes](p,nprimes){
		if(v%p==0){
			a[n++]=p;
			do v/=p;while(v%p==0);
		}
	}
	if(v!=1){
		a[n++]=v;
	}
	return n;
}

struct S{
	unsigned p,q,l,n,f[32],e[32];
	S(){
		rd(p,q);
		//n=Factor(q-=p,f);
		n=factors(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;
}

{
	nprimes=Prime(31622,(int*)primes);
	ll@q;
	rep(q){
		S u,v;
		while(1){
			int 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