This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long lld;
lld a, b, p, q, dy[55][2];
void gcd(lld ix, lld x, lld y){
if(x<y)swap(x,y);
if(y==0){
dy[ix][0]=dy[ix][1]=0;
return;
}
gcd(ix+1, y, x%y);
dy[ix][0]=min(p+dy[ix+1][0], q*(x/y)+dy[ix+1][1]);
dy[ix][1]=min(p+dy[ix][0], q*(x/y)+dy[ix+1][0]);
}
int main(){
int t;
for(scanf("%d",&t); t--;){
scanf("%lld%lld%lld%lld", &a, &b, &p, &q);
gcd(0,a,b);
printf("%lld\n", dy[0][a<b]);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |