Interesting properties of numbers

Sum of digits ( n ) > Sum of digits ( n 3 ) \text{Sum of digits } (n) > \text{Sum of digits } (n^3)

Find the smallest natural number n n such that the above statement is true.

Inspired by this


The answer is 587.

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.

9 solutions

Brock Brown
Mar 17, 2015

Python 2.7:

1
2
3
4
5
6
7
8
def digit_sum(n):
    return sum([int(c) for c in str(n)])
def goal(n):
    return digit_sum(n) > digit_sum(n**3)
n = 0
while not goal(n):
    n += 1
print "Answer:", n

You just wait Brock , I have started leaning Python , in just a few months time I'll be a threat for you !!

Just kidding , there's no way I could be a threat for you :)

Nice solution .

A Former Brilliant Member - 6 years, 2 months ago

I had Bookmarked this site a long time ago , and now it's coming in handy .


For those who don't read the comments below and just want to look at the solution , let me present a solution that my friend Kishlaya has come up with .

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class prog  {

    public static void main (String[] args)
    {
        for(int x=1;;x++) {
            if(sum(x)>sum(x*x*x)) {
                System.out.println(x);
                break;
            }
        }
    }

    static int sum(int n) {
        int sum=0;
        while(n>0) {
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
}

returns 587

I'll try to come up with a Java solution tomorrow .

A Former Brilliant Member - 6 years, 2 months ago

Log in to reply

Here's just a short brute-forcey method (in JAVA)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
class prog  {

    public static void main (String[] args)
    {
        for(int x=1;;x++) {
            if(sum(x)>sum(x*x*x)) {
                System.out.println(x);
                break;
            }
        }
    }

    static int sum(int n) {
        int sum=0;
        while(n>0) {
            sum+=n%10;
            n=n/10;
        }
        return sum;
    }
}

returns 587

Kishlaya Jaiswal - 6 years, 2 months ago

Log in to reply

I had a similar code.

Ronak Agarwal - 6 years, 2 months ago

Nice solution :) +1

How did you give the numbering to the lines of your code ?

A Former Brilliant Member - 6 years, 2 months ago

Log in to reply

@A Former Brilliant Member That's a new feature on B'ant.

Pranjal Jain - 6 years, 2 months ago

Log in to reply

@Pranjal Jain Ok . But how to use it ?

A Former Brilliant Member - 6 years, 2 months ago

Log in to reply

@A Former Brilliant Member Use three tick marks alongwith the programming language name besides it.

image image

Kishlaya Jaiswal - 6 years, 2 months ago

Log in to reply

@Kishlaya Jaiswal Thanks ¨ \ddot\smile

A Former Brilliant Member - 6 years, 2 months ago
Rohan Gupta
Sep 19, 2015

My python 2.7 solution:
for i in range(5000):
a=str(i)
s1=0
for j in a:
s1+=int(j)
s2=0
b=str(i**3)
for k in b:
s2+=int(k)
if s1>s2:
print a




Try Khov
Jul 19, 2015

Mine is a bit convoluted but here is what I did:

Arian Tashakkor
May 18, 2015

My C# code (Uses System.Numeric.dll library for BigInteger)

 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
static void Main(string[] args)
        {
            BigInteger n = 1;
            while (n > 0)
            {
                BigInteger DSn = DigitSum(n);
                BigInteger DSn3 = DigitSum(n * n * n);
                if (DSn>DSn3)
                {
                    Console.WriteLine(n);
                    Console.ReadLine();
                }
                n++;
            }
        }
        public static BigInteger DigitSum(BigInteger n)
        {
            BigInteger num = 0, r, sum = 0;
            num = n;
            while (num > 0)
            {
                r = num % 10;
                num = num / 10;
                sum = sum + r;
            }
            return sum;
        }

\quad

Output = 587

Using javascript. With google chrome, you can easily run this code.

for (x = 1; x <= 1000; x++) { var f1 = String(x), f2 = String(x x x); var n1 = 0, n2 = 0; for (var i in f1) n1 += Number(f1[i]); for (var j in f2) n2 += Number(f2[j]); if (n1 > n2) {alert(x); break;} }

Infinite Loop hehe

Tarun Singh
Mar 19, 2015

C language :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
int ds(int i)    
{
    int s=0;
    while(i>=1)
    {
        s+=i%10;
        i=i/10;
    }
    return s;
}
int main(void)
{
      int j;
      for(j=1;j>0;j++)
      {
          if(ds(j)>ds(j*j*j))
          {
              printf("%d",j);
              break;
          }
      }
}

Aryan Gaikwad
Mar 18, 2015

Java solution -

public static void main(String[] args){
    for(int i = 1;;i++)
        if(sum(i) > sum(i * i * i))
            System.out.println(i);
}

private static int sum(int n){
    int sum = 0;
    while (n != 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

Execution time - 0.000456635 seconds

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...