Suppose two integers x and N.
I’m trying to determine how to construct an algorithm that would return an integer of the value x repeated N times.
So if x was 9 and N was 4, the equation would return 9999.
And if x was 9 and N was 5, the equation would return 99999. (ad nauseam)
I hope this isn’t completely absurd or out of place on SO. 🙂
Note that x is an integer and it does not have to be a 1-digit number in base-10 system. What if N = 3 and x = 12? Then the answer should be 121212.
Here is the solution: we need the length
pof the number x in base-10 system. Letp = floor(lg(x)+1). The number we are searching for isx + x*10^p + x*10^2p + ... + x*10^(N-1)p. That isx * (10^(pN) - 1) / (10^p - 1).