A problem by Rama Devi

I am thinking of a 6-digit number. The sum of the digits is 43.

And only two of the following three statements about the number are true:

(1) it's a square number,

(2) it's a cube number, and

(3) the number is under 500000.

Find the number.


The answer is 499849.

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.

3 solutions

Arulx Z
Jun 21, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
>>> def sum(n):
    s = 0
    while n:
        s += n % 10
        n /= 10
    return s

>>> def sqrt(n):
    for x in xrange(317, 1000):
        z = x ** 2
        if(z == n):
            return True
        elif(z > n):
            return False


>>> def cbrt(n):
    for x in xrange(47, 100):
        z = x ** 3
        if(z == n):
            return True
        elif(z > n):
            return False

>>> for n in xrange(100000,1000000):
    if(sum(n) == 43):
        if(sqrt(n) and cbrt(n)):
            print n
        elif(cbrt(n) and n < 500000):
            print n
        elif(n < 500000 and sqrt(n)):
            print n


499849

Yay! I can finally code in python!

Moderator note:

Congrats on being able to code in Python!

Here 's a C++ solution. Adding it here for the sake of variety.

Prasun Biswas - 5 years, 9 months ago

Did you like the problem ?

Rama Devi - 5 years, 11 months ago

Log in to reply

Yes. I do.

Arulx Z - 5 years, 11 months ago

Log in to reply

Then like and re share it for others.

Rama Devi - 5 years, 11 months ago

Log in to reply

@Rama Devi Please up vote my solution if you like it.

Rama Devi - 5 years, 11 months ago
Rama Devi
Jun 16, 2015

We can deduce that the answer is 499849 by the following steps.

Max sum of numbers is 4+9+9+9+9+9, which equals 49, from this You can deduce that the number is fairly close to the 499999.

It may be a square number. So the square is below square of max sqrt(499999)~707.10607. By trying squares below 707.1.... You will find the right answer that is 707^2.

Only statements 1 and 3 are true because there exists no cube number,whose digits' sum is 43.

I got this wrong, because I failed to read the part that says "only two of the following three statements about this number are true".

But here's some Python anyway:

Python 3.4:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def goal(n):
    count = 0
    if digit_sum(n) == 43:
        if has_root(n,2):
            count += 1
        if has_root(n,3):
            count += 1
        if n < 500000:
            count += 1
    return count == 2
def digit_sum(n):
    return sum((int(i) for i in str(n)))
def has_root(n, root):
    test = 0
    while test**root <= n:
        if test**root == n:
            return True
        test += 1
    return False
n = 100000
while not goal(n):
    n += 1
print("Answer:", n)

Brock Brown - 5 years, 12 months ago

Log in to reply

So , you got trapped.Then why don't you up vote my solution.

Rama Devi - 5 years, 12 months ago

Your solution is incomplete. You didn't show that there is no other number with only satisfies 2 of the 3 statements.

Can you come up with a one line argument why condition 2 cannot be true if the sum of the digits is 43?

Calvin Lin Staff - 5 years, 11 months ago

Log in to reply

I did not mean that 2 cannot be true.

Rama Devi - 5 years, 11 months ago

Log in to reply

I know you did not mean that, nor did you say that. That is why your solution is incomplete, because you didn't show that we could have 1 and 2 being satisfied.

I am saying that

There is no perfect cube whose digit sum is 43.

Calvin Lin Staff - 5 years, 11 months ago

Log in to reply

@Calvin Lin Exactly.That is what I mean.

Any way , thanks, I will edit my solution right now.

Rama Devi - 5 years, 11 months ago

Log in to reply

@Rama Devi Note that you should still explain why "there is no cube number whose digit sum is 43". That is not immediately obvious.

Calvin Lin Staff - 5 years, 11 months ago

Log in to reply

@Calvin Lin How it that possible?

Rama Devi - 5 years, 11 months ago

Log in to reply

@Rama Devi Show that the "cubic residues mod 9" are only 0, 1, 8.

We know that n 3 digit sum of n 3 43 ( m o d 9 ) n^3 \equiv \text{digit sum of } n^3 \equiv 43 \pmod{9} .

Hence, there is no solution.

Calvin Lin Staff - 5 years, 11 months ago
Bill Bell
Sep 17, 2015

Since there aren't many six-digit squares and cubes it's reasonably inexpensive to use a lookup list for them.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
cubes=[c**3 for c in range(47,100)]
squares=[s**2 for s in range(317,1000)]

def sum_digits(n):
    r = 0
    while n:
        r, n = r + n % 10, n / 10
    return r

for n in range(10**5,10**6):
    if sum_digits(n)==43:
        if int(n in squares) + int(n in cubes) + int(n<500000)==2:
            print n

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...