Find the smallest positive integer n such that the first 10 digits of 3 n contain all the digits from 0 to 9 exactly once each.
Clarification: For example, the first 4 digits of 3 2 = 1 . 2 5 9 9 2 … are 1, 2, 5, and 9.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Isn't that an amazing property of 2017?
Log in to reply
Yes, it is! How did you come to notice this?
Log in to reply
Playing around with a calculator. :P :P
Then I did a similar, but longer brute force script on Python to find out some numbers which satisfied. Turned out 2017 was the first that did so, though 304 works if we were to look at 10 significant figures.
A shorter solution in python, could be:
1 2 3 4 5 6 |
|
Output
Idk but your code is showing timeout error?! on online judge
Log in to reply
Try it on https://ideone.com
Code in python 3.
No way to do this on paper?
Log in to reply
This is a Computer Science problem, it should be solved using program only.
Basically, I start with n = 2 and I evaluate 3 n for each loop. Now I take each digit d i ∈ [ 0 , 1 , . . . , 9 ] , 1 ≤ i ≤ 1 0 and I put it in an empty array A such that A d i = d i . For example, if I'm looking at the 5 th digit of the root whose value is 6 ( d 5 = 6 ), I'll put it in A 6 . If d i = 0 , than A 1 0 = 0 . If I'm looking at a digit for the second time, its place in A will be already occupied and than the loop stops and goes for n + 1 . The algorithm finds a solution when A = [ 1 , 2 , 3 , . . . , 0 ] .
MATLAB code:
Problem Loading...
Note Loading...
Set Loading...
The tricky part is to evaluate the decimals, but we can keep multiplying it by 10 until we have the first 10 digits. To check if all numbers are unique, throw everything into a set, which by definition doesn't contain duplicates, and the length should be 10.