woensdag 16 maart 2011

Euler problem 38

Take the number 192 and multiply it by each of 1, 2, and 3:
192 × 1 = 192
192 × 2 = 384
192 × 3 = 576
By concatenating each product we get the 1 to 9 pandigital, 192384576. We will call 192384576 the concatenated product of 192 and (1,2,3)
The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).
What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product of an integer with (1,2, ... , n) where n > 1?


Analyse:
     
Because the Euler website returns 918273645 as an incorrect answer we must find a greater pandigital number. 
Axioma 1: The pandigital must start with digit 9!
     
Search for values of n and M which yield to a 9 digit pandigital.
     
        M       Pandigital      Result (S = to short, L = to long)
        ======= =============== ======
n=2     9       918             S
        9x      9x1xx           S
        9xx     9xx1xxx         S
        9xxx    9xxx1xxxx       Okee (9 digits)
n=3     9       91827           S
        9x      9x1xx2xx        S
        9xx     9xx1xxx2xxx3xxx L
n=4     9       9182736         S
        9x      9x1xx2xx3xx4xx  L
n=5     9       918273645       Okee (website says incorrect )
        9x      9x1xx2xx3xx4xx  L
n=6     9       91827364554     L
     
So the only possibility is n = 2 and M is 9xxx.
The definition of a pandigital says that all digits must be different so start with M = 9876 and count down to 9123.
The resulting number is M plus N = M plus 2M = M*100000 + 2*M = M * 100002 





Problem38 =   932718654 elapsed time:    0 ms. Test Passed.

Geen opmerkingen:

Een reactie posten