I'm doing a project euler problem (http://projecteuler.net/problem=40) that requires iteration of each digit of a set of increasing integers, in order.
I solved it by converting each integer to a string and taking the 0 index, but I'd like to know if there's a better, numerical algorithm to find the most significant digit of an arbitrarily long given integer.
Example: Given 3918287712, to easily get both (3) and find the power of 10 (10^10) that corresponds to it. I'd really like pointers to mathematical literature as well - I'm trying to increase my own knowledge of math and algorithms.
Arithmetically, the number of digits of a positive integer $N$ is $d=\lfloor \log_{10} N\rfloor + 1$. For example, $\log_{10} 3918287712 \approx 9.5931$, so $3918287712$ has $\lfloor 9.5931\rfloor + 1 = 10$ digits.
Once you know the number of digits $d$ of $N$, you can find the first digit $f$ of $N$ by calculating $f = \lfloor N/10^{d-1} \rfloor$. For example, the first digit of $3918287712$ is $\lfloor 3918287712/10^{10-1} \rfloor = \lfloor 3.918287712 \rfloor = 3$.
(In practice, your string-based method might be faster...!)