Given two positive integer sequences {ai} and {bj} (0 < ai, bj < 100), calculate the continued fraction generated by those two sequences.
The continued fraction x is defined as:
.png)
For example, if the sequences {ai} is {2, 7, 3} and {bj} is {3, 2, 2}, then the answer should be 3/(2 + 7/(2 + 2/(3 + 1))) = 5/8
Note that your answer should be expressed in simplest terms. That is, 2/4 should be represented as 1/2. If the answer is an integer then the denominator should be showed as 1. For example, 3 should be represented as 3/1.
Hint:
You may use the following incomplete code to solve the problem:
#include <stdio.h>
int a[10], b[10];
int gcd(int a, int b)
{
/* your code here */
}
int main(void)
{
int i, n;
int de, nu;
int tmp, g;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
nu = 1;
de = 1;
for (i = 0; i < n; i++) {
/* your code here */
}
printf("%d %d\n", nu, de);
return 0;
}
The length of the sequence (0 < n < 10).
a1 b1
a2 b2
…
an bn
The output is a pair of numerator and denominator, ended with a newline character.