# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
6812 | gs12117 | 분수 (KPI13_fractions) | C++98 | 0 ms | 1088 KiB |
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>
long long int n;
long long int a,b,c,d;
long long int x[100];
long long int y[100];
long long int xl,yl;
int main(){
long long int i,j,t;
scanf("%lld",&n);
for(i=0;i<n;i++){
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
for(xl=0;;xl++){
if(b==0)break;
x[xl]=a/b;
t=a%b;
a=b;
b=t;
}
for(yl=0;;yl++){
if(d==0)break;
y[yl]=c/d;
t=c%d;
c=d;
d=t;
}
for(j=0;;j++){
if(x[j]!=y[j]||j==xl||j==yl)break;
}
if(j==xl){
x[j]=y[j]+1;
}
else if(j==yl){
x[j]=x[j]+1;
}
else if(x[j]<y[j]){
if(j==yl-1&&x[j]+1==y[j]){
if(j==xl-2&&x[j+1]==2){
j++;
x[j]=1;
j++;
x[j]=2;
}
else{
if(xl!=j+1&&x[j+1]==1){
x[j]++;
}
j++;
x[j]=2;
}
}
else{
x[j]++;
}
}
else{
if(j==xl-1&&y[j]+1==x[j]){
if(j==yl-2&&y[j+1]==2){
x[j]=y[j];
j++;
x[j]=1;
j++;
x[j]=2;
}
else{
x[j]=y[j];
if(yl!=j+1&&y[j+1]==1){
x[j]++;
}
j++;
x[j]=2;
}
}
else{
x[j]=y[j]+1;
}
}
a=1;
b=0;
while(j>=0){
t=a;
a=b;
b=t;
a+=x[j]*b;
j--;
}
printf("%lld %lld\n",a,b);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |