Đề bài:
Lời giải hiện tại của em, chưa thể nộp được vì mắc lỗi TLE
/* coder: Anh Tuan Nguyen */
#include <bits/stdc++.h>
using namespace std;
int main()
{
#ifdef gsdt
freopen("input.txt","r",stdin);
#endif // gsdt
int T;
scanf("%d",&T);
while(T--)
{
uint64_t res=INT_MAX;
uint64_t A,B,C,D;
//bool ok=true;
scanf("%I64d%I64d%I64d%I64d",&A,&B,&C,&D);
for(int q=0; q<10000000000; q++)
{
if(A<B) swap(A,B), swap(C,D);
uint64_t r=A-B;
if(r<res)
{
res=r;
/*cout<<A<<" "<<B<<" "<<"["<<res<<"]"<<endl;
if(A<=0||B<=0||res==0)
{
cout<<"Q="<<q<<endl;
break;
}*/
//ok=false;
}
if(r>D) B+=D*(r/D);
else B+=D;
//if(A==B)cout<<A<<" "<<B<<endl;
}
printf("%I64d\n",res);
}
return 0;
}
Mong các anh chị giúp em ý tưởng.
)
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?