IMO training problem

Logic Level 3

Given a positive integer n n , let p ( n ) p(n) be the product of the non-zero digits of n n . (If n n has one digit, then p ( n ) p(n) is equal to that digit.) Let

S = p ( 1 ) + p ( 2 ) + + p ( 999 ) . S = p(1) + p(2) + \cdots + p(999).

What is the largest prime factor of S S ?


The answer is 103.

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.

6 solutions

Sharky Kesa
Feb 22, 2014

Consider each positive integer less than 1000 to be a three-digit number by prefixing 0s to numbers with fewer than 3 digits. The sum of the products of the digits of all such positive numbers is

( 0 0 0 + 0 0 1 + . . . + 9 9 9 ) 0 0 0 (0 \cdot 0 \cdot 0 + 0 \cdot 0 \cdot 1 + ... + 9 \cdot 9 \cdot 9) - 0 \cdot 0 \cdot 0

Note that each product appears once, thrice or 6 times depending on the number of repeated digits it has, so we get that the product is = ( 0 + 1 + . . . + 9 ) 3 0 =(0 + 1 + ... + 9)^3 - 0 .

However, p ( n ) p(n) is the product of non-zero digits of n n . The sum of these products can be found by replacing 0 by 1 in the above expression, since ignoring 0's is equivalent to thinking of them as 1's in the products. (Note that the final 0 in the above expression becomes a 1 and compensates for the contribution of 000 after it is changed to 111.) Hence

S = 4 6 3 1 = ( 46 1 ) ( 4 6 2 + 46 + 1 ) = 3 3 5 7 103 S = 46^3 - 1 = (46 - 1)(46^2 + 46 + 1) = 3^3 \cdot 5 \cdot 7 \cdot 103

and the largest prime factor is 103.

Its a question of AIME 1994

jinay patel - 7 years, 3 months ago

Log in to reply

Exactly, I was wondering why this problem seemed so familiar. It would be nice, though, if everyone could post some new original problems.

Daniel Liu - 7 years, 3 months ago

Log in to reply

I think posting problems from some mathematics competition is great for others who doesn't take part on that competition especially those that is not available for downloads.

Christopher Boo - 7 years, 3 months ago

Sometimes it's hard to think of new problems when you're so busy. Sorry for any inconvenience.

Sharky Kesa - 7 years, 3 months ago

Please provide some insight for the process that gets you from step 1 to step 2, the sum of products to the cube of a sum.

Brian Tonks - 4 years, 11 months ago

Log in to reply

That would be useful...

Dan Ley - 4 years, 10 months ago

My biggest question is how would you factor out a number like 46^3 - 1. I used the difference of cubes but didn't get any further..

Newton Migosi - 1 year, 6 months ago

Log in to reply

You can explicitly evaluate 4 6 2 + 46 + 1 = 2163 = 7 × 309 = 7 × 3 × 103 46^2 + 46 + 1 = 2163 = 7 \times 309 = 7 \times 3 \times 103 .

Sharky Kesa - 1 year, 6 months ago

Lets rewrite the first 99 99 and then we will multiply that by 1 1 , then by 2 2 , \ldots , then by 9 9 . Lets say that

S 1 = [ ( 1 + 2 + + 9 ) + 1 + 1 ( 1 + 2 + + 9 ) + 2 + 2 ( 1 + 2 + + 9 ) + + 9 + 9 ( 1 + 2 + + 9 ) ] S_{1} = [(1 + 2 + \ldots + 9) + 1 + 1(1 + 2 + \ldots + 9) + 2 + 2(1 + 2 + \ldots + 9) + \ldots + 9 + 9(1 + 2 + \ldots + 9)]

This is equivalent to

S 1 = 1 ( 45 ) + 1 ( 46 ) + 2 ( 46 ) + + 9 ( 46 ) S_{1} = 1(45) + 1(46) + 2(46) + \ldots + 9(46)

S 1 = 45 ( 47 ) S_{1} = 45(47)

S 1 S_{1} is the sum from 1 1 to 99 99 . We'll have extra numbers in our sum ( 100 100 , 200 200 , \ldots, 900 900 ), and hence when we multiply 45 47 45\cdot 47 by the hundreds digit of the numbers, we need to add 1 1 . So, it's the same than multiplying 46 46 46\cdot 46 which is equal to 45 47 + 1 45\cdot 47 + 1 . So,

S = S 1 + ( S 1 + 1 ) + 2 ( S 1 + 1 ) + + 9 ( S 1 + 1 ) S = S_{1} + (S_{1} + 1) + 2(S_{1} + 1) + \ldots + 9(S_{1} + 1)

S = 2115 + 45 ( 2116 ) S = 2115 + 45(2116)

We can factorize carefully in many ways, but i like this one:

S = 2115 ( 46 ) + 45 = 9 ( 235 46 + 5 ) S = 2115(46) + 45 = 9(235\cdot 46 + 5)

S = 3 3 5 7 103 S = 3^{3} \cdot 5 \cdot 7 \cdot 103

And therefore, the largest prime factor is:

103 \boxed {103} .

i solved same way..

amit kumar - 6 years, 7 months ago

Me too, same method:)

Dan Ley - 4 years, 10 months ago
Cody Johnson
Feb 24, 2014

When 0 0 digits are equal to 0 0 , we sum through a = 1 9 b = 1 9 c = 1 9 a b c = 4 5 3 \sum_{a=1}^9\sum_{b=1}^9\sum_{c=1}^9abc=45^3 . When 1 1 digit is equal to 0 0 , we sum through a = 1 9 b = 1 9 a b = 4 5 2 \sum_{a=1}^9\sum_{b=1}^9ab=45^2 , but there are three cases, accounting for 3 4 5 2 3\cdot45^2 . When there are 2 2 digits, it's 3 45 3\cdot45 . All 3 3 cannot be 0 0 . Hence, the sum is 4 5 3 + 3 4 5 2 + 3 45 = 4 6 3 1 45^3+3\cdot45^2+3\cdot45=46^3-1 which has the largest prime factor of 103 \boxed{103} .

The simplest solution.

Isra kheder - 4 years, 9 months ago
Carsten Meyer
Mar 30, 2021

Let k N k\in\mathbb{N} , and N k : = { 1 0 k 1 ; ; 1 0 k 1 } N_k := \{10^{k-1};\:\ldots;\: 10^k-1\} be the set of positive integers with exactly k k digits. Define

S k : = i = 1 1 0 k 1 p ( i ) , S 1 = i = 1 9 i = 9 10 2 = 45 We need to compute S 3 \begin{aligned} S_k &:=\sum_{i=1}^{10^k-1}p(i), &&& S_1 &=\sum_{i=1}^9 i= \frac{9\cdot 10}{2}=45&&&&&\left|\:\text{We need to compute }S_3\right. \end{aligned}

Check for a recursive relation. Notice any integer in N k + 1 N_{k+1} consists of a non-zero first digit \text{\yellow{non-zero first digit}} , followed either by an integer in N k \green{N_k} , or 0 \red{0} : S k + 1 = S k + i N k + 1 p ( i ) = S k + ( 1 + + 9 ) ( S k + 1 ) = S k + 45 ( S k + 1 ) = 46 S k + 45 \begin{aligned} S_{k+1} &= S_k + \sum_{i\in N_{k+1}} p(i) = S_k + \left(\yellow{1 + \ldots + 9}\right) \cdot \left(\green{S_k} + \red{1}\right)=S_k+45(S_k+1)=46S_k + 45 \end{aligned}

By induction, we get S k = 4 6 k 1 , S 3 = 4 6 3 1 = 97335 = 3 3 5 7 103 \begin{aligned} S_k &= 46^k - 1, &&&&& S_3 &=46^3-1=97335=3^3\cdot 5\cdot 7 \cdot\boxed{103} \end{aligned}

K T
Feb 18, 2019

Let x,y,z be nonzero digits.

x = 1 9 y = 1 9 z = 1 9 p ( x y z ) = 4 5 3 \sum_{x=1}^{9} \sum_{y=1}^{9} \sum_{z=1}^{9}p(\overline{xyz})=45^3

x = 1 9 y = 1 9 p ( x y 0 ) = x = 1 9 z = 1 9 p ( x 0 z ) = y = 1 9 z = 1 9 p ( y z ) = 4 5 2 \sum_{x=1}^{9} \sum_{y=1}^{9}  p(\overline{xy0})= \sum_{x=1}^{9} \sum_{z=1}^{9}  p(\overline{x0z})= \sum_{y=1}^{9} \sum_{z=1}^{9}  p(\overline{yz})=45^2

x = 1 9 p ( x 00 ) = y = 1 9 p ( y 0 ) = z = 1 9 p ( z ) = 45 \sum_{x=1}^{9}  p(\overline{x00})= \sum_{y=1}^{9}  p(\overline{y0})= \sum_{z=1}^{9}  p(\overline{z})=45

4 5 3 + 3 × 4 5 2 + 3 × 45 = 45 ( 4 5 2 + 3 × 46 ) = 45 × 2163 = 3 3 × 5 × 7 × 103 45^3+3×45^2+3×45=45(45^2+3×46)=45×2163=3^3×5×7×\boxed{103}

Simon Jarvers
Jan 7, 2019

This is quite a brute force ansatz with code for matlab. The final sum will be 97335 which can be found to have 103 as it's largest primefactor.

The variables stand for the german words for

h = Hunderter = hundreds

z = Zehner = tens

e = Einser = ones

finalsum = 0;
tempsum = 0;
for h = 0:9
for z = 0:9
    for e = 0:9
        if h == 0
            if z == 0
                tempsum = e;
            elseif z > 0
                if e == 0
                    tempsum = z;
                elseif e > 0 
                    tempsum = z*e;
                end
            end
        elseif h > 0
            if z == 0
                if e == 0
                    tempsum = h;
                elseif e > 0 
                    tempsum = h*e;
                end
            elseif z > 0
                if e == 0
                    tempsum = h*z;
                elseif e > 0 
                    tempsum = h*z*e;
                end
            end
        end
        finalsum = finalsum + tempsum;
    end
end
end
finalsum

Good as far as it goes, but just for completeness here's a python function to return the highest prime factor. It just keeps dividing by prime factors until the result is a prime. Apologies for the name; I may be writing this later at night than I should be.

def maxfactor(n):

i = 2

while i!= n:
    if n%i == 0:
        n = n//i
    else:
        i = i+1

return i

Richard Farrer - 2 years, 4 months ago

Apologies...but gentleman this code is not returning correct value

Tanishq kokcha - 1 year, 1 month ago

Log in to reply

I think this code works

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import numpy as np
from sympy.ntheory import factorint

# treat zero as one
def cvt(n): 
    if n == '0': return 1
    return int(n)

psum = 0 
for n in range(1, 1000):
    digits = list(map(cvt, str(n)))
    psum += np.prod(digits)

maxprime = sorted(factorint(int(psum)).keys(), reverse=True)[0]
print(psum, maxprime)

# 97335 103

Fletcher Mattox - 10 months, 3 weeks ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...