+ 1
Problem: 1/n cycle
1/7 = 0.142857 142857 142857 .... We see that the decimal part has a cycle: 142857. The length of this cycle is 6. In the same way: 1/11 = 0.09 09 09 .... Cycle length is 2. Task Given an integer n (n > 1) the function cycle(n) returns the length of the cycle if there is one otherwise (n and 10 not coprimes) return -1. How do find out the length of the repetiting part after the dot. I dont know the condition statement in for loop for iteration
4 Antworten
+ 5
I would like to choose
a solution based on recursive algorithm.
You take first two digits and check with the next two. If they not equal you will take one more digit etc.
+ 1
maybe you can modify this:
https://www.geeksforgeeks.org/find-recurring-sequence-fraction/
into something like this:
https://code.sololearn.com/chR949iXH1B0/?ref=app
wiki page for repeating decimals
https://en.wikipedia.org/wiki/Repeating_decimal
0
Are you given the numbers as a string or just n and its 1/n every time?
0
If you're printing to high precision then you could use something like this so you don't have precision loss.
https://code.sololearn.com/c0f6WDjCv0tz/?ref=app