bincycle - n There will be multiple data sets each data set...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 Repeating Binary Fractions --------- ------ --------- The decimal representation of rational numbers is always either finite or involves a `repeating fraction'. For instance, the rational number 1/3 has the decimal repre- sentation 0.33333. .. or 0.(3) if we adopt the convention that the repeating part shall be given in parentheses. The rational number 1/7 has the decimal representation 0.142857142857142857. .. or 0.(142857) Similarly, 1/12 can be represented as 0.083333. .. or 0.08(3) and 1/2 can be represented as 0.5000. .. or 0.5(0) This is true in bases other than 10. For instance, in base 2, the fraction 1/3 has the representation 0.0101010101. .. or 0.(01) and the fraction 10/24 = (3 + 1/3)/8 has the repre- sentation 0.01101010101. .. or .011(01) Your task is to write a program that will find, for a given rational number, the number of digits in the repeating portion of the binary representation. This number is called the `period' of the repeating portion.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: n There will be multiple data sets each data set will contain two strictly positive (> 0) integers on a single line. These two integers define an input number, which equals the first integer divided by the second integer, so the input number is a fraction with the first integer as numerator and the second integer as denominator. Output for each data set should be a single line containing just the period of the repeating portion of the binary representation of the input number. The period will always be one or greater and will always be less than or equal to the denominator. The denominator will be less than 10,000,000. Sheet1 Page 2 Hint: The resource limits (See Makefile) forbid a solution whose memory size is linear in the denominator or whose time is quadratic in the denominator. Sample input: 1 12 1 3 10 24 4 8 8 4 2 7 6251832 8954347 Sample output: 2 2 2 1 1 3 8954346...
View Full Document

This note was uploaded on 04/29/2011 for the course IT 201 taught by Professor K.v.arya during the Spring '11 term at IIT Kanpur.

Page1 / 2

bincycle - n There will be multiple data sets each data set...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online