It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.
Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
analyse:
Lets say we have a number n. According the problem description the number 6*n must have the same number of digits.
this is only the case when the number n starts with digit 1. i.e. n = 1000 6n = 6000 (both four digits) n = 2000 6n = 12000. n and 6n have resp. 4 and 5 digits so they can never have the same digits.
more precisely, n must be between 1000 and 1666 (=9999/6)
performance improvements:
Use bitmap to store digits. 50 -> 8 ms.

Geen opmerkingen:
Een reactie posten