An automorphic number is a number whose square ends in the same digits as the number itself. For example, the number 25 is an automorphic number (in base 10) because its square, 6 25 , ends with the original number.
For the first 100 positive integers, five numbers are automorphic numbers for base 10 (1, 5, 6, 25, and 76), while only one number is automorphic for base 2 (1).
Which of the following bases has the most automorphic numbers for the first 100 positive integers?
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.
Wow, nice work!
The following code first defines a function to represent any number in any base, provided the base is less than 37. Another function is defined to test whether a number is automorphic in a given base. Finally, the first 100 positive integers are tested for automorphism in each base, and the automorphic numbers and their squares are displayed both in base 10 and the tested base. The result of the code is displayed at the bottom.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
1 2 3 4 5 |
|
Nice solution! I wonder if I should change the topic of this question to "Computer Science"
Log in to reply
That might make sense, but I feel like there is some discussion that could be had on it regarding number theory. I was intending to come back to this and add more ways of looking at it. But honestly even those are mostly in the realm of computer science. I haven't figured out anything purely mathematical that reduces the amount of work to solve the problem, but I am curious to know if there is anything.
So yes, it looks like there was a lot of computer science involved, but there was some number theory as well. Ultimately, I think it's number theory, because any improvements to the process come from number theory. I might even say it's reasonable to do it by hand once you really whittle it down.
I found another way to test for automorphism. For some reason I doubted that I had it right at first, thinking there were many exceptions, so I didn't post it, but it turns out it's pretty straightforward. It still involves figuring out some properties of the number represented in the tested base, so it's not actually that much easier, and you still have to test for each for the same quantity of numbers.
The test is simply that n 2 − n be divisible by b k , where b is the base and k is the number of digits in n when represented in base b . If this is true, then the n is automorphic; the same is true for the converse. The proof is simply that if n 2 − n is divisible by b k , then n 2 mod b k is n ; since b k in base b is simply 1 0 0 ⋯ 0 with k zeros, this removes from n 2 (base b ) all digits preceding the last k , and thus the last k digits of n 2 (base b ) are the same as those of n .
The tricky part is just figuring out k , but this is simpler than completely representing numbers in the given base. So the new code could be written as below. This method reduces lines of code and computation time (although, as written, this is not an apples-to-apples comparison because I have also simplifies the output):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 |
|
Another way to reduce computation time is by eliminating numbers that can't be automorphic as you go. There are two examples I found:
This is basically dynamic programming (#2), plus a little extra speed (#1). An interesting thing here is that now we have to keep track of the number of digits for two reasons:
With all these changes, it is easiest to combine everything into a single set of nested loops; there is no need to define functions like before.
We also might as well automatically start with "1" in each list of automorphic numbers since 1 will be automorphic in all bases (but this improvement doesn't scale). Finally, we modify the code as follows, which gives the same output as before but faster:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Problem Loading...
Note Loading...
Set Loading...
Here are the lists of *automorphic bases" for the first one hundred (decimal) positive integers for bases from 2 to 100, selected for the list not being just {1}, sorted first by length of the list descending and then by base value for equal length lists. This was done by direct computation, in a single line of code.
SortBy [ Select [ Table [ { base , Table [ n = IntegerDigits [ i , base ] ; If [ n = Take [ IntegerDigits [ i 2 , base ] , − Length [ n ] ] , i , Nothing ] , { i , 1 0 0 } ] } , { base , 2 , 1 0 0 } ] , $#$1 [ [ 2 ] ] = { 1 } & ] , { − Length [ $#$1 [ [ 2 ] ] ] & , $#$1 [ [ 1 ] ] & } ] ⇒ ⎝ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ ⎜ 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 ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎟ ⎞