
Repeating Decimal or Expanding Fraction
Moderator: Board moderators
-
- Experienced poster
- Posts: 101
- Joined: Wed May 04, 2005 4:33 pm
- Location: Tangerang, Banten, Indonesia
- Contact:
Repeating Decimal or Expanding Fraction
Can someone explain to me how to find the repeating decimal or expanding fraction (202 and 275) from 2 integers? The algorithm only is OK. I've no idea with this problem. Thanx in advance 

Hi Roby,
I try to help you.
The number in decimal is repeated if when you divide them with the divisor they have same remainders appear twice.
I try explain you with sample input from problem 275.
input :
3 7
output :
.428571
The last 6 digits repeat forever.
output '.'
N
1. multiply 3 by 10
30 / 7 = 4 , output 4
30 % 7 = 2 (remember this value)
2. multiply 2 by 10
20 / 7 = 2, output 2
20 % 7 = 6 (remember this value)
3. multiply 6 by 10
60 / 7 = 8, output 8
60 % 7 = 4 (remember this value)
4. multiply 4 by 10
40 / 7 = 5, output 5
40 % 7 = 5 (remember this value)
5. multiply 5 by 10
50 / 7 = 7, output 7
50 % 7 = 1 (remember this value)
6. multiply 1 by 10
10 / 7 = 1, output 1
10 % 7 = 3 (remember this value)
7. multiply 3 by 10
30 / 7 = 4, output 4
30 % 7 = 2 (2 is appear twice)
to know how many digits repeat just output when :
(second time appear) - (first time appear)
in the example above first time '2' appear when N=1;
second time '2' appear when N=7;
so output 7-1 = 6.
6 digits repeat forever.
I hope you understand what I mean and can get AC.
Sorry for my poor English.

I try to help you.
The number in decimal is repeated if when you divide them with the divisor they have same remainders appear twice.
I try explain you with sample input from problem 275.
input :
3 7
output :
.428571
The last 6 digits repeat forever.
output '.'
N
1. multiply 3 by 10
30 / 7 = 4 , output 4
30 % 7 = 2 (remember this value)
2. multiply 2 by 10
20 / 7 = 2, output 2
20 % 7 = 6 (remember this value)
3. multiply 6 by 10
60 / 7 = 8, output 8
60 % 7 = 4 (remember this value)
4. multiply 4 by 10
40 / 7 = 5, output 5
40 % 7 = 5 (remember this value)
5. multiply 5 by 10
50 / 7 = 7, output 7
50 % 7 = 1 (remember this value)
6. multiply 1 by 10
10 / 7 = 1, output 1
10 % 7 = 3 (remember this value)
7. multiply 3 by 10
30 / 7 = 4, output 4
30 % 7 = 2 (2 is appear twice)
to know how many digits repeat just output when :
(second time appear) - (first time appear)
in the example above first time '2' appear when N=1;
second time '2' appear when N=7;
so output 7-1 = 6.
6 digits repeat forever.
I hope you understand what I mean and can get AC.
Sorry for my poor English.

"Life is more beautiful with algorithm"