More mean numbers

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 d 1 d 2 d 6 d 7 \overline{d_1d_2\ldots d_6d_7} are there such that d 1 × d 2 × × d 6 = ( d 7 ) 6 , d_1\times d_2\times \cdots \times d_6 = (d_7)^6, where 1 d i 9 ? 1 \leq d_i \leq 9?

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.


The answer is 1889.

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.

2 solutions

Arjen Vreugdenhil
Jan 22, 2018

A mathematical approach .

In general, if d p , i d_{p,i} is the exponent of prime number p p in digit d i d_i , we must have i = 1 6 d p , i = 6 d p , 7 . \sum_{i = 1}^6 d_{p,i} = 6d_{p,7}. This requires that i = 1 6 d p , i \sum_{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 a_d for the number of times digit d d occurs among the first six digits. Naturally, a 1 + a 2 + + a 9 = 6 a_1 + a_2 + \cdots + 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. \sum_{i=1}^6 d_{2,i} = a_2 + a_6 + 2a_4 + 3a_8;\ \ \sum_{i=1}^6 d_{3,i} = a_3 + a_6 + 2a_9; \\ \sum_{i=1}^6 d_{p,i} = a_p\ \ \ \text{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 a_1, a_2, \dots, a_9 , then there are ( 6 a 1 a 2 a 3 a 9 ) = 6 ! a 1 ! a 2 ! a 9 ! \binom{6}{a_1\ \ a_2\ \ a_3\ \ \dots\ \ a_9} = \frac{6!}{a_1! a_2!\cdots a_9!} numbers with the given numbers of each digit.

With this preparation, consider the possible values for the last digit, a 7 a_7 .

  • If d 7 = 1 , 5 , 7 , 8 , 9 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 1111111 , 5555555 , 7777777 , 8888888 , 9999999 1111111, 5555555, 7777777, 8888888, 9999999 .

  • If d 7 = 3 d_7 = 3 , then the number can only contain the digits 1, 3, and 9. We have a 1 = a 9 = : a a_1 = a_9 =: a and a 3 = 6 2 a a_3 = 6 - 2a . Clearly, the possible values of a a range from 0 to 3, so we calculate a = 0 3 ( 6 a a 6 2 a ) = 6 ! 0 ! 0 ! 6 ! + 6 ! 1 ! 1 ! 4 ! + 6 ! 2 ! 2 ! 2 ! + 6 ! 3 ! 3 ! 0 ! = 1 + 30 + 90 + 20 = 141. \sum_{a=0}^3 \binom{6}{a\ \ a\ \ 6-2a} = \frac{6!}{0! 0! 6!} + \frac{6!}{1! 1! 4!} + \frac{6!}{2! 2! 2!} + \frac{6!}{3! 3! 0!} = 1 + 30 + 90 + 20 = 141. This is the number of solutions ending in 3 3 ; they are all permutations of 333333 333333 , 1333393 1333393 , 1133993 1133993 and 1119993 1119993 .

  • If d 7 = 2 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 a_1 = a_4 + 2a_8 . If a 1 > 4 a_1 > 4 then a 8 > 2 a_8 > 2 , which would make for too many digits in total; this we must consider 0 a 1 4 0 \leq a_1 \leq 4 . Then 0 2 a 8 a 1 0 \leq 2a_8 \leq a_1 . Thus, the count of numbers ending in 2 is a 1 = 0 4 a 8 = 0 a 1 / 2 ( 6 a 1 a 8 a 1 2 a 8 6 2 a 1 + a 8 ) \sum_{a_1=0}^4 \sum_{a_8=0}^{\lfloor a_1/2 \rfloor} \binom{6}{a_1\ \ \ a_8\ \ \ a_1 - 2a_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 ! = 1 + 30 + 90 + 60 + 20 + 120 + 15 = 336. = \frac{6!}{0! 0! 0! 6!} + \frac{6!}{1! 0! 1! 4!} + \frac{6!}{2! 0! 2! 2!} + \frac{6!}{2! 1! 0! 3!} + \frac{6!}{3! 0! 3! 0!} + \frac{6!}{3! 1! 1! 1!} + \frac{6!}{4! 2! 0! 0!} = 1 + 30 + 90 + 60 + 20 + 120 + 15 = 336.

  • For d 7 = 4 d_7 = 4 we use a trick: "translate" all digits according to 1 8 1 \leftrightarrow 8 and 2 4 2 \leftrightarrow 4 , and you have the previous case. Thus, another 336 336 numbers ends in 4.

  • What remains is the case d 7 = 6 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 \begin{cases} a_1 + a_3 + a_9 = a_4 + 2a_8 =: x; \\ a_1 + a_2 + a_4 + a_8 = a_9 \end{cases} \ \ \ \therefore\ \ \ \begin{cases} a_1 + z + a_3 = a_8 =: x; \\ z + a_4 = a_9 - x := y \\ a_1 + a_2 := z \end{cases} 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 ) ( 6 x x + y y z a 1 z a 1 x z a 1 6 3 x 2 y + z + a 1 ) . \sum_{x=0}^2 \sum_{y = 0}^{3 - x} \sum_{z = 0}^{\text{min}(x,y)} \sum_{a_1 = 0}^{\text{min}(z, x-z)} \binom{6}{x \ \ \ x+y \ \ \ y - z \ \ \ a_1 \ \ \ z - a_1 \ \ \ x - z - a_1 \ \ \ 6 - 3x - 2y + z + a_1}.
    We find the following terms; the right column shows examples of the numbers that are being counted. x y z 0 0 0 1 6666666 0 1 0 30 4666696 0 2 0 90 4466996 0 3 0 20 4449996 1 0 0 120 3666896 1 1 0 360 3468996 1 1 1 180 2668996 1 2 1 120 2489996 2 0 0 90 3388996 2 1 1 60 1889996 1101 \begin{array}{ccc|rl} x & y & z & & & \\ \hline 0 & 0 & 0 & 1 & 6666666 \\ 0 & 1 & 0 & 30 & 4666696 \\ 0 & 2 & 0 & 90 & 4466996 \\ 0 & 3 & 0 & 20 & 4449996 \\ 1 & 0 & 0 & 120 & 3666896 \\ 1 & 1 & 0 & 360 & 3468996 \\ 1 & 1 & 1 & 180 & 2668996 \\ 1 & 2 & 1 & 120 & 2489996 \\ 2 & 0 & 0 & 90 & 3388996 \\ 2 & 1 & 1 & 60 & 1889996 \\ \hline & & & 1101 & \end{array}

Thus we find a total of 5 + 141 + 2 × 336 + 1101 = 1889 5 + 141 + 2\times 336 + 1101 = \boxed{1889} solutions.


Here is a solution in code .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>

int main() {
    int i, n, nn, d[7], p1, p2, count;

    count = 0;
    for (n = 1000000; n <= 9999999; n++) {
        nn = n; p1 = 1; p2 = 1;
        for (i = 0; i < 7; i++) {
            d[i] = nn % 10; nn /= 10;
            if (i > 0) { p1 *= d[i]; p2 *= d[0]; }
        }

        if (p1 > 0 && p1 == p2) {
            printf("%d\n",n);
            count++;
        }
    }

    printf("%d\n",count); 
}

This program lists all 1889 \boxed{1889} numbers that qualify.

Giorgos K.
Feb 5, 2018

Mathematica

Length@Select[Range[10^6,10^7],GeometricMean[(s=IntegerDigits[#])[[1;;6]]]==s[[7]]&&s~FreeQ~0&]

Doesn't that statement produce one solution too many, namely 10 000 000 10\,000\,000 ?

Arjen Vreugdenhil - 3 years, 4 months ago

Log in to reply

of course not. 10.000.000 contains many zeroes....(see more carefully the last part of my code)

Giorgos K. - 3 years, 4 months ago

Log in to reply

I see, you threw out anything with zeroes.

Arjen Vreugdenhil - 3 years, 4 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...