Product of Digits

Let P ( n ) P(n) denotes the product of all nonzero digits of n n . Evaluate P ( 1 ) + P ( 2 ) + P ( 3 ) + + P ( 999 ) P(1) +P(2) + P(3) +\cdots+P(999) .


Source : AIME


The answer is 97335.

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.

8 solutions

Kunal Verma
Mar 19, 2015

F o r d i g i t s f r o m 1 t o 9 , t h e s u m i s : 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 N e x t , f o r 10 t o 19 : 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 T h e n f o r 20 t o 29 : 2 ( 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) A n d s o o n t i l l 99. T h u s , l e t s t a k e S = 1 + 1 + 2 + 3 + 4 + 5 + 6 + 8 + 9 T h u s , f o r d i g i t s t i l l 99 w e h a v e . S + S + 2 S + 3 S + 4 S + 5 S + 6 S + 7 S + 8 S + 9 S = 46 S N o w f o r 100 t o 999 : 1 × 1 × S + 1 × 2 × S . . . + 1 × 9 × S + 2 × 1 × S + 2 × 2 × S . . . + 9 × 9 × S A d d i n g a l l , w e g e t : ( 46 × 46 × S ) 1 ( B e c a u s e t h e r e s o n e 1 l e s s i n f i r s t i n f i r s t s t e p ) = 46 3 1 = 97335 For\quad digits\quad from\quad 1\quad to\quad 9,\quad the\quad sum\quad is:-\\ \\ 1\quad +\quad 2\quad +\quad 3\quad +\quad 4\quad +\quad 5\quad +\quad 6\quad +\quad 7\quad +\quad 8\quad +\quad 9\quad \\ \\ Next,\quad for\quad 10\quad to\quad 19:-\\ \\ 1\quad +\quad 1\quad +\quad 2\quad +\quad 3\quad +\quad 4\quad +\quad 5\quad +\quad 6\quad +\quad \\ 7\quad +\quad 8\quad +\quad 9\quad \\ \\ Then\quad for\quad 20\quad to\quad 29:-\\ \\ 2(\quad 1\quad +\quad 1\quad +\quad 2\quad +\quad 3\quad +\quad 4\quad +\quad 5\quad +\quad 6\quad \\ +\quad 7\quad +\quad 8\quad +\quad 9)\\ \\ And\quad so\quad on\quad till\quad 99.\\ \\ Thus,\quad let's\quad take\quad S\quad =\quad 1\quad +\quad 1\quad +\quad 2\quad +\quad 3\quad +\quad 4\quad +\quad 5\quad \\ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad +\quad 6\quad +\quad 8\quad +\quad 9\\ \\ Thus,\quad for\quad digits\quad till\quad 99\quad we\quad have.\\ \\ S\quad +\quad S\quad +\quad 2S\quad +\quad 3S\quad +\quad 4S\quad +\quad 5S\quad +\quad 6S\quad +\quad 7S\\ +8S\quad +\quad 9S\quad =\quad 46S\\ \\ Now\quad for\quad 100\quad to\quad 999:-\\ \\ \quad 1\quad \times \quad 1\quad \times \quad S\\ +1\quad \times \quad 2\quad \times \quad S\\ .\\ .\\ .\\ +1\quad \times \quad 9\quad \times \quad S\\ +2\quad \times \quad 1\quad \times \quad S\\ +2\quad \times \quad 2\quad \times \quad S\\ .\\ .\\ .\\ +9\quad \times \quad 9\quad \times \quad S\\ \\ Adding\quad all,\quad we\quad get:-\\ (46\quad \times \quad 46\quad \times \quad S)\quad -\quad 1\quad (Because\quad there's\quad one\quad 1\quad less\\ \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad in\quad first\quad in\quad first\quad step)\\ =\quad { 46 }^{ 3 }\quad -\quad 1\\ =\quad \boxed { 97335 }

I did (1+2+3+4+5+6+7+8+9)=45

3 × 45 + 3 × 4 5 2 + 4 5 3 = 97335 3×45 + 3×45^2 + 45^3 = \boxed {97335}

The first term covers the one digit numbers (from 1 to 9) and the "round" tens and hundreds (10, 20, ..., 90 and 100, 200, ..., 900);

the second term is the sum regarding those two digit numbers, which don't have any zero digits and those three digit numbers, which have exactly one zero digit;

and the last term those 3 digit numbers, which don't have a zero digit.

Zee Ell - 5 years, 5 months ago

Well done. Me too same way.

Chandrachur Banerjee - 6 years ago
John Samuel
Jun 24, 2015

I worked out the answer but I couldnt resist to work out for the general case, and the result is beautiful, here it goes

sum |n= 1 to 999 P(n)

can be be written as

sum |n= 1 to 10^3 - 1 P(n)

or in general sum |i = 1 to 10^n - 1 P(i), where n> 0

then, sum |i = 1 to 10^n - 1 P(i) = 45* { sum |j=0 to n-1 (46^j-1) }

or simply

sum |i = 1 to 10^n - 1 P(i) = 45*(1 + 46 + 46^2 + ...... + 46^n-1)

example:
sum |i = 1 to 9 P(i) = 45*(1) = 45

sum |i = 1 to 99 P(i) = 45*(1 + 46^1) = 2115

sum |i = 1 to 999 P(i) = 45*(1 + 46^1 + 46^2) = 97335 (Current Problem)

sum |i = 1 to 9999 P(i) = 45*(1 + 46^1 + 46^2 + 46^3) = 4477455

sum |i = 1 to 99999 P(i) = 45*(1 + 46^1 + 46^2 + 46^3 + 46^4) = 205962975

sum |i = 1 to 999999 P(i) = 45*(1 + 46^1 + 46^2 + 46^3 + 46^4 + 46^5) = 9474296895

.

.

.

sum |i = 1 to 10^n -1 P(i) = 45*(1 + 46^1 + 46^2 + .......46^n-1) - General case

It can also be shown that all sums are mulitples of 9

Brock probably should use the above formula on his program, to save a lot of his computational power, resource and time.

45+(1+45) ((45+2) 45)

Shubham Garg
Jun 17, 2015

Let S = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 45 S=1+2+3+4+5+6+7+8+9=45

( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) × ( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) (1+2+3+4+5+6+7+8+9) \times (1+2+3+4+5+6+7+8+9)

It forms all the possible combinations of the two digit expect the ones with
zeroes . ( 1 × 9 m e a n s 19 a n d 9 × 1 m e a n s p r o d u c t o f d i g i t s o f 91 ) (1 \times 9 \quad means \quad 19 \quad and \quad 9\times 1\quad means\quad product \quad of \quad digits \quad of \quad 91)

Now the one with zeroes there are two possible cases that is zero at tens place(single digit integer) or at units place . In both case the sum is S S .

So the sum of products for two digit nos is ( S 2 + 2 S ) = 2115 (S^2+2 S)= \boxed{2115 }

For the three digit numbers

( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) × ( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) × ( 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) (1+2+3+4+5+6+7+8+9) \times (1+2+3+4+5+6+7+8+9) \times (1+2+3+4+5+6+7+8+9)

( 9 × 9 × 3 m e a n s p r o d u c t o f d i g i t s o f 993 ) (9 \times 9 \times 3 \quad means\quad product \quad of \quad digits \quad of \quad 993)

forms all the possible combinations of the three digit nos expect the ones with
zeroes .

if there is one zero it can come at units place or tens for both the cases

the sum will be S 2 S^2 like mentioned above

when there are two zeroes the sum will be S S ( c a s e i n c l u d e s 100 , 200........900 ) (case \quad includes \quad 100,200........900) .

total sum for three digit numbers is S 3 + 2 S 2 + S = 95220 S^3+2S^2+S=\boxed{95220}

Therefore the total sum is 2115 + 95220 = 97335 2115+95220=97335

Brock Brown
Mar 8, 2015

Python:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def p(n):
    product = 1
    for digit in str(n):
        if digit != '0':
            product *= int(digit)
    return product
total = 0
for n in xrange(1,1000):
    total += p(n)
print "Answer:", total

Really????? Oh Genius solution indeed!!! Euler would have been proud!!

Chandrachur Banerjee - 6 years ago

Log in to reply

Is that sarcasm?

Julian Poon - 6 years ago

Log in to reply

Oh i didn't know that in any country solving ingenious number theory problems using a computer was considered brilliance. The downvotes for my above quote proves that. BUT That isn't allowed in my country. And i am proud of it.

Chandrachur Banerjee - 5 years, 11 months ago

If u think it otherwise do pay time to your english (THIS IS A JOKE). Ha Ha. Lol.

Chandrachur Banerjee - 5 years, 11 months ago
Keanu Ac
May 8, 2017

1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 = 46 46 accounts for the 1s, then for the tens, then for the hundreds. 46 x 46 x 46, then - 1 because for the first ten, the sum is 45 whereas the rest are 46.

Ravi Dwivedi
Dec 1, 2015

Write each number in the form of a three digit number e.g. 005 005 and 019 019 We remove the zeros and replace each zero by 1 1 since that does not change the product.

Notice ( 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) ( 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) ( 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) (1+1+2+3+4+5+6+7+8+9)(1+1+2+3+4+5+6+7+8+9)(1+1+2+3+4+5+6+7+8+9) have the product of every 3 3 digits. But 000 000 is not included so subtract 1 1 .

Answer = ( 1 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 ) 3 1 = 4 6 3 1 = 97335 (1+1+2+3+4+5+6+7+8+9)^{3} -1=46^3-1 = \boxed{97335}

Moderator note:

"We remove the zeros and replace each zero by 1 1 since that does not change the product" should still use a line of explanation for why "the product of non-zero terms is not changed".

The bijection is not expressed in a clear manner for others to understand. You should explain how it is set up / created, while would allow one to follow your argument easily. For example, it is not immediately clear why 000 has appeared, and why "so subtract 1".

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...