Quote Originally Posted by Mario F. View Post
Elegant The 0 could just be counted. The problem however is that the repeating division will increase O beyond n, no?

If you can find a way to reduce the number in one pass...
I wouldn't consider the divisions to influence the order, because the number of divisions depends on the magnitude of the elements, not the number of elements. Assuming 32-bit integers, you'd never need to divide more than 20 times per element, because 3^21 overflows the range of a 32-bit unsigned int.

But I don't know how to work around the big problem which is 2*x1+xk divisible by three.. I get a feeling like there's a workable method here but I haven't found it yet.