Many thanks for the pointers. BitIntegers.jl has Int256, Int512 and Int1024 types! That’s great. I think I need Int512, and the first test was very nice (for the recursive function the allocated memory, and running time, went down dramatically).
With BigInt:
julia> @time brute_force(10,63)
:BigInt[59, 53, 51, 48, 47, 43, 42, 41, 37, 35, 33, 31, 26, 25, 23, 22, 20, 19, 18, 17, 14, 9, 6, 5, 1] 9.849302918817908e17 0
32.820850 seconds (392.13 M allocations: 8.765 GiB, 27.37% gc time)
false
With Int512:
julia> @time brute_force(10,63)
:Int512[59, 53, 51, 48, 47, 43, 42, 41, 37, 35, 33, 31, 26, 25, 23, 22, 20, 19, 18, 17, 14, 9, 6, 5, 1] 9.849302918817908e17 0
5.154979 seconds (5.38 k allocations: 331.125 KiB)
false
For the iterative function I still need to check what is going on, because the running time goes down from 52 to 24 seconds, but the allocated memory actually increases to 58GiB.
But overall very promising, thanks.
(And yes, I do need all those digits
Well, at some point I will have to rethink the algorithm and perhaps then I can do it some other way, but at this moment I need to perform accurate addition/subtraction of really big numbers, with totals of about 100 digits).