How many seven-digit positive numbers, containing no zeroes, are there such that the geometric mean of the first six digits is equal to the seventh digit?
In other words, how many distinct numbers are there such that where
It is probably easier to write code to solve this problem. However, a mathematical solution using combinatorics might be more interesting!
This is a follow-up on this problem , but more elaborate.
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.
A mathematical approach .
In general, if d p , i is the exponent of prime number p in digit d i , we must have i = 1 ∑ 6 d p , i = 6 d p , 7 . This requires that ∑ i = 1 6 d p , i is a multiple of six. Note also that there is only one digit that combines two different primes, namely 6.
Write a d for the number of times digit d occurs among the first six digits. Naturally, a 1 + a 2 + ⋯ + a 9 = 6 . Then i = 1 ∑ 6 d 2 , i = a 2 + a 6 + 2 a 4 + 3 a 8 ; i = 1 ∑ 6 d 3 , i = a 3 + a 6 + 2 a 9 ; i = 1 ∑ 6 d p , i = a p for p = 5 , 7 .
We have a solution if all of these four sums are a multiple of six. Moreover, once we know values for a 1 , a 2 , … , a 9 , then there are ( a 1 a 2 a 3 … a 9 6 ) = a 1 ! a 2 ! ⋯ a 9 ! 6 ! numbers with the given numbers of each digit.
With this preparation, consider the possible values for the last digit, a 7 .
If d 7 = 1 , 5 , 7 , 8 , 9 , there is only one way to fulfill the conditions: all digits should be equal. (This is easy to prove.) This gives the 5 solutions 1 1 1 1 1 1 1 , 5 5 5 5 5 5 5 , 7 7 7 7 7 7 7 , 8 8 8 8 8 8 8 , 9 9 9 9 9 9 9 .
If d 7 = 3 , then the number can only contain the digits 1, 3, and 9. We have a 1 = a 9 = : a and a 3 = 6 − 2 a . Clearly, the possible values of a range from 0 to 3, so we calculate a = 0 ∑ 3 ( a a 6 − 2 a 6 ) = 0 ! 0 ! 6 ! 6 ! + 1 ! 1 ! 4 ! 6 ! + 2 ! 2 ! 2 ! 6 ! + 3 ! 3 ! 0 ! 6 ! = 1 + 3 0 + 9 0 + 2 0 = 1 4 1 . This is the number of solutions ending in 3 ; they are all permutations of 3 3 3 3 3 3 , 1 3 3 3 3 9 3 , 1 1 3 3 9 9 3 and 1 1 1 9 9 9 3 .
If d 7 = 2 , then the number can only contain the digits 1, 2, 4, and 8. We have a 1 = a 4 + 2 a 8 . If a 1 > 4 then a 8 > 2 , which would make for too many digits in total; this we must consider 0 ≤ a 1 ≤ 4 . Then 0 ≤ 2 a 8 ≤ a 1 . Thus, the count of numbers ending in 2 is a 1 = 0 ∑ 4 a 8 = 0 ∑ ⌊ a 1 / 2 ⌋ ( a 1 a 8 a 1 − 2 a 8 6 − 2 a 1 + a 8 6 ) = 0 ! 0 ! 0 ! 6 ! 6 ! + 1 ! 0 ! 1 ! 4 ! 6 ! + 2 ! 0 ! 2 ! 2 ! 6 ! + 2 ! 1 ! 0 ! 3 ! 6 ! + 3 ! 0 ! 3 ! 0 ! 6 ! + 3 ! 1 ! 1 ! 1 ! 6 ! + 4 ! 2 ! 0 ! 0 ! 6 ! = 1 + 3 0 + 9 0 + 6 0 + 2 0 + 1 2 0 + 1 5 = 3 3 6 .
For d 7 = 4 we use a trick: "translate" all digits according to 1 ↔ 8 and 2 ↔ 4 , and you have the previous case. Thus, another 3 3 6 numbers ends in 4.
What remains is the case d 7 = 6 . Considering the prime factors 2 and 3 separately, we have { a 1 + a 3 + a 9 = a 4 + 2 a 8 = : x ; a 1 + a 2 + a 4 + a 8 = a 9 ∴ \ ⎩ ⎪ ⎨ ⎪ ⎧ a 1 + z + a 3 = a 8 = : x ; z + a 4 = a 9 − x : = y a 1 + a 2 : = z Thus, the count of numbers ending in 6 is equal to x = 0 ∑ 2 y = 0 ∑ 3 − x z = 0 ∑ min ( x , y ) a 1 = 0 ∑ min ( z , x − z ) ( x x + y y − z a 1 z − a 1 x − z − a 1 6 − 3 x − 2 y + z + a 1 6 ) .
We find the following terms; the right column shows examples of the numbers that are being counted. x 0 0 0 0 1 1 1 1 2 2 y 0 1 2 3 0 1 1 2 0 1 z 0 0 0 0 0 0 1 1 0 1 1 3 0 9 0 2 0 1 2 0 3 6 0 1 8 0 1 2 0 9 0 6 0 1 1 0 1 6 6 6 6 6 6 6 4 6 6 6 6 9 6 4 4 6 6 9 9 6 4 4 4 9 9 9 6 3 6 6 6 8 9 6 3 4 6 8 9 9 6 2 6 6 8 9 9 6 2 4 8 9 9 9 6 3 3 8 8 9 9 6 1 8 8 9 9 9 6
Thus we find a total of 5 + 1 4 1 + 2 × 3 3 6 + 1 1 0 1 = 1 8 8 9 solutions.
Here is a solution in code .
This program lists all 1 8 8 9 numbers that qualify.