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