Problem 51715. Iterate the sum of divisors and totient
Cody Problem 46898 deals with the sum of divisors function, denoted by
, while Cody Problem 656 deals with the totient function, denoted by
. The sum of divisors is straightforward: for example,
. The totient of n counts the numbers less than n that are relatively prime to n. For example
because the greatest common divisor of 12 and four numbers (1, 5, 7, 11) is 1.
What happens if you repeatedly apply the two functions, starting with the sum of divisors and alternating? For example, start with 7. Then
and the pattern 7, 6, 12, 4 will repeat.
Oscillating behavior is plausible because the sum of divisors is always greater than n, and the totient is always smaller than n. Furthermore, because the totient has a minimum value and the sum of divisors has a maximum value, with enough iterations the sequence would have to hit a repeating pattern.
Write a function that takes an initial seed and returns the repeating pattern and the index of the sequence where the pattern begins. With an initial seed of 7, the sequence would be 7, 8, 4, 7, 6, 12, 4, 7, 6, 12,… Therefore, the repeating pattern is [7 6 12 4] and the start index is 3.
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
David Hill
on 10 May 2021
Chris,
Would you check test17. I get a repeating pattern starting at index 161 that has 36 members.
ChrisR
on 10 May 2021
Yes, I do too. Not sure what happened or why my reference solution worked. Thanks, David.
goc3
on 7 May 2022
An interesting and challenging problem. I feel that it should be worth more than ten points...
Rafael S.T. Vieira
on 27 Nov 2022
The greatest challenge is to produce the most optimized code. Writing code that works is easy.
Solution Comments
Show commentsProblem Recent Solvers14
Suggested Problems
-
813 Solvers
-
513 Solvers
-
107 Solvers
-
142 Solvers
-
145 Solvers
More from this Author271
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!