As of version 3.8, it is well-known that python treats tail recursion poorly and it by default has a low recursion depth. Although sys.setrecursionlimit(limit)
seems to bypass this problem, at some larger inputs a segmentation fault is raised indefinitely.
There is no workaround. Therefore, the program will be written in later versions as an iterative form, rather than recursive.
Aside: related PEP's
- PEP 651: Robust Stack Overflow Handling (created 18-Jan-2021)