Project Euler 197 - Investigating the behaviour of a recursively defined sequence

Official link: https://projecteuler.net/problem=197