A fraction in lowest terms has a decimal that ends exactly when its bottom has no prime factor other than and . You will strip those factors away and test a list of fractions, without dividing.
The idea. Divide the bottom by while you can, then by while you can. If is left, the decimal ends. Reduce the fraction first, with gcd.
Your tasks.
strip, return what is left of q after taking out every and every .ends, reduce p / q and return True when its decimal ends.enders with the fractions in fractions whose decimals end.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…