Ok, I ended up using two classes.
- One supports the expansion of a number in positional numeral system with custom radix.
- One maintains the prime integer factorization of a number.
Both classes aim to support efficient increment-with-one operations. The former (the expansion) can start from arbitrary number, but the latter (the factorization) starts from 0 only. The purpose is to have incremental factorization of consecutive numbers. I didn't bother to implement booting from arbitrary point.
The expansion holds array of 'digits'. The factorization holds array of 'expansions' with radix-es for each prime number less than the current quantity.
The increment-with-one of the expansions returns the multiplicity of the radix as divisor. This equals the number of trailing zeros in the expansion and is easy to compute from (is actually equal to) the number of carries during the increment.
The increment operation of the factorization returns the total number of divisors for the new value. Computes them according to the rule in my last post (the second edit:), using the multiplicity returned from the expansions. It can detect prime numbers easily, because they have only trivial divisors. In this case a new expansion is created with this prime number as radix and is added to the list.
I use lists. I could rearrange stuff to use vectors for locality of access, although since the lists are allocated right after program start-up they are in consecutive addresses and considering that the memory consumption is low, probably everything gets cached.
The added memory consumption is roughly in the kilos, but the main processing loop does not work from registers anymore, as would be the case with the direct solution. I think there is some trade-off. On my box the result is computed in about 3/4 of a second in debug mode and under decisecond in release mode.
All this business works because I compute the divisors of the two consecutive factors of the triangle number, and consecutive numbers are coprime (they have no common divisors). This means that the number of divisors for the doubled triangle number is the product from the number of divisors of its two consecutive factors. I still needed a (moderately ugly) hack for that halving thing. Also, here is a nice article:
http://en.wikipedia.org/wiki/Pronic_number.
Regards