Find the smallest integer such that when is written in base 12 , it has 121 trailing zeros . Enter your answer in base 6 .
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.
Disclaimer: I am relatively new in writing solutions, so I see myself as blind when it comes to telling the difference between pseudo-maths and maths-maths. If you happen to catch anything odd in this solution, please reply. If any of my "theories" are wrong, please reply as well so that everybody may benefit. :-)
Initial Thoughts of the Mind
1 2 can be prime factored into 2 2 × 3 . Furthermore, N ! can be factored into 1 2 a × k where a is the number of trailing zeroes and 1 2 ∤ k . From 1 2 a = 4 a × 3 a = 2 2 a × 3 a , it follows that we need to find min ( ⌊ 2 v 2 ( N ) ⌋ , v 3 ( N ) ) where the function v p ( n ) is given as: v p ( n ) = i = 1 ∑ k ⌊ p i n ⌋ = ⌊ p n ⌋ + ⌊ p 2 n ⌋ + ⌊ p 3 n ⌋ + ⋯ + ⌊ p k n ⌋ , where k = ⌊ lo g p n ⌋ .
Note that we floor 2 v 2 ( N ) to ignore any decimal points and remainders obtained from dividing by 2.
To simplify things, perhaps it might be possible to theorise which prime number (either 2 or 3 ) will be sparser throughout the product of the factorial N ! . When dealing with base 1 0 , we could theorise that 5 is sparser relative to 2 and as such, we only counted the highest power of 5 . With 2 and 3 however, it's rather difficult to tell. With base 1 0 , 2 2 < 5 , so we are reassured that the ratio of 2 's and 5 ’s will eventually reach or exceed 2 : 1. With base 1 2 , each 3 has to be compensated with two 2 's. However, we aren't guaranteed that the growth will be entirely linear and keep a 2 : 1 ratio between the number of 2 ’s and the number of 3 ’s because 3 < 2 2 . In this solution, I chose to count the number of 3's.
Developing a Fast Algorithm
Let's first obtain a rough estimate of our integer N . We could do a linear search starting from 1 all the way up to our integer N but that would take much too long to test (for some, at least).
Instead, we can make use of the geometric-series-sum formula: S = 1 − r u 1 ( 1 − r n ) , where u 1 is the first term of the sequence, r is the common ratio between consecutive terms, and n is the number of terms in the geometric progression.
Now how can we apply this formula? Firstly, we can treat the summation of v p ( n ) as a sequence of integers a m ∀ m ∈ Z . Treating this as a sequence, we can take a 0 = N then iterate through all a i = ⌊ p a i − 1 ⌋ where 1 ≤ i ≤ k , k = ⌊ lo g p n ⌋ . Also from the theorem of v p ( n ) , we may observe each consecutive term experiencing a multiplicative factor of p 1 . We will use this multiplicative factor as our common ratio, r .
We shall remove the mapping of the floor function for the simplicity of the geometric-series summation. (Note that, by waiving the floor function, we are subjecting our sum to an accumulation of continuous values. And this is the cause for the inaccuracy of this part of the algorithm, regardless of the fact that it's quick to use).
We can obtain an estimate for v p ( n ) by using the geometric-series-sum formula stated above and ignoring the floor function. (Mind though, that this will often lead to an estimate of v p ( n ) , and not its exact value.) By doing this, we have a convenient way of pinpointing the whereabouts of N .
We shall state this function as w p ( n ) : w p ( n ) = i = 1 ∑ k p i n = 1 − p 1 n ( 1 − p k 1 ) − n , where k = ⌊ lo g p n ⌋ .
To clarify the use of subtracting n at the end, we need to acknowledge that n itself is not supposedly part of our sum. We consider it the a 0 but our summation officially begins for a i when i = 1 .
Further simplification using algebra brings us to w p ( n ) = p k ( p − 1 ) n ( p k − 1 )
To further simplify the equation, we could also treat the sequence from our previous theorems as an infinite geometric progression. By summing an infinite progression, smaller and smaller values will keep being added. As i approaches zero, a i approaches 0. The series converges due to our common ratio, r = p 1 being in between − 1 and 1 (to be more precise, 0 < r < 1 as we will never be getting a negative prime, p ).
The sum of an infinite geometric progression goes: S = 1 − r u 1 , where u 1 is the first term of the progression and r is the common ratio.
Thus, we could restate w p ( n ) as w p ( n ) = i = 1 ∑ ∞ p i n = 1 − p 1 n − n Further algebraic simplification leads us to w p ( n ) = p − 1 n
Keep in mind that our current w p ( n ) is not entirely the same function as our previous w p ( n ) . Further consequences involve a less accurate value returned and a higher deviation from the exact value.
This, however, provides a straight-forward function to use since it is easy to manipulate and isolate variables.
Solving the Problem: Finding N
w p ( n ) will only provide us an estimate. We might possibly need to do a linear search and check every number after applying the formula for w 3 ( n ) = 1 2 1 . w 3 ( n ) 1 2 1 1 2 1 n = 3 − 1 n = 2 n = 2 n = 2 4 2
Using this estimate of N , we can test this value (and possibly consecutive values) using v p ( n ) . First we count the number of 2 's using v 2 ( 2 4 2 ) : v 2 ( 2 4 2 ) = ⌊ 2 1 2 4 2 ⌋ + ⌊ 2 2 2 4 2 ⌋ + ⋯ + ⌊ 2 7 2 4 2 ⌋ = 2 3 7 We stop at 2 7 since ⌊ lo g 2 2 4 2 ⌋ = 7 .
We also need to count the number of 3 's using v 3 ( 2 4 2 ) : v 3 ( 2 4 2 ) = ⌊ 3 1 2 4 2 ⌋ + ⌊ 3 2 2 4 2 ⌋ + ⋯ + ⌊ 3 4 2 4 2 ⌋ = 1 1 6 Likewise, we stop at 3 4 as ⌊ lo g 3 2 4 2 ⌋ = 4 .
Computing min ( ⌊ 2 v 2 ( N ) ⌋ , v 3 ( N ) ) gives us 1 1 6 which is only 5 zeroes away from our goal. We shall now apply a linear search method and accumulate our zeroes starting from N = 2 4 3 by first prime factorising N .
2 4 3 = 3 5
We can add five 3 's to our already existing one-hundred-(and)-sixteen 3 's, giving us (currently) a grand total of 2 2 3 7 and 3 1 2 1 . Yay, we reached 121!!! Indeed, that may be a cause for celebration, but computing min ( ⌊ 2 v 2 ( N ) ⌋ , v 3 ( N ) ) unfortunately gives us 118. This is due to v 2 ( N ) having a value of 237. Ah, so now we need to ensure that there will be at least 242 (or 243) 2 's and at least 121 3 's. Let's keep this in mind now (if you already had this in mind, good on you).
2 4 4 = 2 2 × 6 1 1 Grand Total: 2 2 3 9 , 3 1 2 1
2 4 5 = 5 1 × 7 2 Grand Total: 2 2 3 9 , 3 1 2 1
2 4 6 = 2 1 × 3 1 × 4 1 1 Grand Total: 2 2 4 0 , 3 1 2 2
We have exceeded 121 3 's, so now we are hoping that there will be 2 or 3 more 2 's in store for us.
2 4 7 ... skip this, no factors of 2 or 3 here.
2 4 8 = 2 3 × 3 1 Grand Total: 2 2 4 3 , 3 1 2 2 .
We have reached a point where we have 243 2 's and 122 3 's. Going any further with higher values of N will only give us more factors of 2 and 3 to worry about. 248 is our smallest integer N such that when N ! is written in base 12 , it has 121 trailing zeroes (restating statement from question). 249 is also a possible candidate since min ( ⌊ 2 v 2 ( N ) ⌋ , v 3 ( N ) ) also equals 1 2 1 . However, we shall hang on tight to 248 since it is our smallest candidate.
Solving the Problem: Converting to Base 6
A method of converting any number, M 1 0 from base 1 0 to base x is to find the highest power i of x such that x i ≤ M 1 0 . A way to start off is to draw a 'T' table listing pairs of i and x i . The table for x = 6 is listed below for values of i up to i = ⌊ lo g 6 2 4 8 ⌋ = 3 .
|| 3 || 2 1 6 ||
Now we shall iterate through values of x i starting from the largest value (i.e. 2 1 6 ). As we iterate, we shall write a i in the form a i = b i × 6 i + a i − 1 (as in a = b × q + r ) so that a i − 1 < 6 i . We shall then note down the value of b i then repeat for a i − 1 . Our numeric conversion terminates once i = 0 . (There is probably a neat algorithmic approach to notate this paragraph, but I couldn't get it right.) Keep in mind that a m a x ( i ) = M 1 0 . In our current case, a 3 = 2 4 8 .
2 4 8 3 2 3 2 2 = 1 × 6 3 + 3 2 = 0 × 6 2 + 3 2 = 5 × 6 1 + 2 = 2 × 6 0 + 0
We may conclude that 2 4 8 1 0 = 1 0 5 2 6 and 1 0 5 2 6 is the smallest integer in base 6 that when 1 0 5 2 6 ! is written in base 12, it has 121 trailing zeroes □ .