Submission #66351127


Source Code Expand

/*
*            /$$           /$$
*           |__/          |__/
*  /$$$$$$$$ /$$ /$$$$$$$$ /$$  /$$$$$$
* |____ /$$/| $$|____ /$$/| $$ /$$__  $$
*    /$$$$/ | $$   /$$$$/ | $$| $$  \ $$
*   /$$__/  | $$  /$$__/  | $$| $$  | $$
*  /$$$$$$$$| $$ /$$$$$$$$| $$|  $$$$$$$
* |________/|__/|________/|__/ \____  $$
*                                   | $$
*                                   | $$
*                                   |__/
*/
//hj23308保佑我
//Missile保佑我
/*
* 醒了在梦里挣扎,不觉黯淡了朝霞
*/
/*
* 我很高兴你没有忘了我,但是我现在更希望你已经忘了我了。
* 希望在你的记忆中,我只是尘土一撮,从你的全世界路过,然后四散飞扬不留下一点痕迹,而你要不回头的往前走。
* 我更希望我只是从你的全世界路过,只是路过
*/
/*
* 只是我在十字路口守了太久,守到黄沙如雨掩埋一切痕迹,才发现自己等的人已经离开了。
*/
/*
* 听我的 别回头 回头就可能会泪流满面,会被黄沙掩埋,所以即使痛苦也要向前走
*/
/*
* 我听到了「天行健」的回响,这是一个伟大斗士的不息自强;
* 我听到了「破万法」的回响,这是一个黑道打手的守护欲望;
* 我看见了「生生不息」的激荡,这是一个骗子的伟大乐章!
*/
/*
* 我用虚假的面具照顾着细腻的感情;
* 我以华丽的衣物下藏着腐烂的血肉;
* 当我摘下面具,褪去衣物,即便是我最亲近的人,也无法直视我
*/
#include<bits/stdc++.h>
using namespace std;
int t;
long long A,B,C,D;
void exgcd(long long A,long long B,long long C,long long D,long long &p,long long &q)
{
	if(D==0||((A/B)<((C+D-1)/D)-1)) {
		p=(A+B)/B,q=1;
		return;
	}
	long long t=(A/B);
	exgcd(D,C-D*t,B,A-B*t,p,q);
	long long op=p,oq=q;
	q=op;
	p=oq+t*q;
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--) {
		cin>>A>>B>>C>>D;
		long long gA=__gcd(A,B),gB=__gcd(C,D);
		A/=gA,B/=gA,C/=gB,D/=gB;
		long long p,q;
		exgcd(A,B,C,D,p,q);
		cout<<q<<"\n";
	}
	return 0;
}

Submission Info

Submission Time
Task G - A/B < p/q < C/D
User Ziziq
Language C++ 20 (gcc 12.2)
Score 625
Code Size 2234 Byte
Status AC
Exec Time 447 ms
Memory 4404 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 625 / 625
Status
AC × 1
AC × 35
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 01_handmade_06.txt, 01_handmade_07.txt, 01_handmade_08.txt, 01_handmade_09.txt, 01_handmade_10.txt, 01_handmade_11.txt, 01_handmade_12.txt, 01_handmade_13.txt, 01_handmade_14.txt, 01_handmade_15.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3472 KiB
01_handmade_00.txt AC 11 ms 3256 KiB
01_handmade_01.txt AC 2 ms 3616 KiB
01_handmade_02.txt AC 447 ms 4212 KiB
01_handmade_03.txt AC 397 ms 4096 KiB
01_handmade_04.txt AC 395 ms 4160 KiB
01_handmade_05.txt AC 172 ms 3448 KiB
01_handmade_06.txt AC 64 ms 4404 KiB
01_handmade_07.txt AC 187 ms 3388 KiB
01_handmade_08.txt AC 191 ms 3332 KiB
01_handmade_09.txt AC 67 ms 4212 KiB
01_handmade_10.txt AC 65 ms 4184 KiB
01_handmade_11.txt AC 67 ms 4204 KiB
01_handmade_12.txt AC 67 ms 4172 KiB
01_handmade_13.txt AC 68 ms 4268 KiB
01_handmade_14.txt AC 63 ms 4228 KiB
01_handmade_15.txt AC 64 ms 3956 KiB
02_random_00.txt AC 202 ms 3404 KiB
02_random_01.txt AC 198 ms 3388 KiB
02_random_02.txt AC 201 ms 3480 KiB
02_random_03.txt AC 197 ms 3500 KiB
02_random_04.txt AC 203 ms 3492 KiB
02_random_05.txt AC 204 ms 3400 KiB
02_random_06.txt AC 184 ms 3404 KiB
02_random_07.txt AC 184 ms 3468 KiB
02_random_08.txt AC 171 ms 3452 KiB
02_random_09.txt AC 174 ms 3472 KiB
02_random_10.txt AC 196 ms 3384 KiB
02_random_11.txt AC 193 ms 3432 KiB
02_random_12.txt AC 195 ms 3460 KiB
02_random_13.txt AC 196 ms 3396 KiB
02_random_14.txt AC 193 ms 3396 KiB
02_random_15.txt AC 193 ms 3616 KiB
02_random_16.txt AC 150 ms 3480 KiB
02_random_17.txt AC 150 ms 3464 KiB