Question: Simplify continued fractions expansion?

I'm trying to use the continued fractions expansion to simplify a fraction, and I need to cut the expansion off for large values (for example when a denominator is greater than 20). I have a list of the outputs but I'm struggling to find the correct commands to use in order to do this.

p := ContinuedFraction((q-1)/2^t);
print(p);
cf := Term(p, 0..100);
print(cf);
R := Convergent( p, 100);
r := denom(R);
printf("The order is %d"\n, r);
 

This is the section of code, any help would be appreciated, thanks.

Please Wait...