Let S ( n ) denote the sum of the digits of an positive integer n .
Find the smallest positive integer x such that S ( x ) > S ( x 2 ) .
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.
I'm curious about whether the set of all x such that S ( x ) > S ( x 2 ) is finite or infinite. A proof would need some number theory, but I'm wondering if your program can be adapted to find higher values up to a set limit, just to get an idea of how common such x are.
Log in to reply
The set is infinite.
Hint: There is a very obvious family of solutions, starting with 39.
Hint: What is 1 0 2 ?
Log in to reply
But S ( 1 0 n ) = S ( 1 0 2 n ) for all non-negative integers n , and we are looking for x such that S ( x ) > S ( x 2 ) .
Log in to reply
@Brian Charlesworth – Obviously my hints are not immediately applicable.
There is a small intermediary step.
Log in to reply
@Calvin Lin – Got it. Should have thought for a few more seconds before commenting. :P
I still dont get it. Lol. Would you mind explaining a little more?
Log in to reply
@Trevor Arashiro – We would have S ( 3 9 ∗ 1 0 n ) = S ( 3 9 ) and S ( ( 3 9 ∗ 1 0 n ) 2 ) = S ( 3 9 2 ∗ 1 0 2 n ) = S ( 3 9 2 ) for any non-negative integer n , since all we would be doing is adding 0 's at the end and hence not changing the digit sum.
Thus since S ( 3 9 ) > S ( 3 9 2 ) , we have S ( 3 9 ∗ 1 0 n ) > S ( ( 3 9 ∗ 1 0 n ) 2 ) for all non-negative integers n , making the set of all such x infinite. The next question would be: are there an infinite number of distinct solution "families", i.e., an infinite number of "base" numbers such as 3 9 that are not multiples of 1 0 of one another?
Log in to reply
@Brian Charlesworth – Once again, there is an obvious family of solutions to try. In fact, there are infinitely many families of solutions, all starting with 39, and not containing a multiple of 10. We can make each of these families disjoint (with the exception of the initial term 39).
Hint: If something works, don't break it.
Hint: What is 1 0 0 0 2 ?
@Brian Charlesworth – For clarity, the sequence that I'm referring to is
3 9 , 3 9 0 0 0 3 9 , 3 9 0 0 0 0 0 0 3 9 , 3 9 0 0 0 0 0 0 0 3 9 , …
where we add enough 0's so that the cross terms do not matter (and can only help). We could also use terms like 39000003900000000000000039, for variety.
The set of all x is looking pretty infinite to me.
Have fun!
Python 2.7:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Log in to reply
Hahaha. "#until it gets tired". :) Thanks for doing this. At least now I know that infinite is the likely target.
Please look if there is any number theory approach and please post it.
Can you post a more efficient solution here ? Thanks.
For a change, I decided to use a spreadsheet to do this. The formulas keyed in are as follows:
A2: 1 B2: =INT(A2/10) C2: =A2-10*B2 D2: =B2+C2 E2: =A2*A2 F2: =INT(E2/1000) G2: =INT((E2-1000*F2)/100) H2: =INT((E2-1000*F2-100*G2)/10) I2: =E2-1000*F2-100*G2-10*H2 J2: =F2+G2+H2+I2 K2: =D2>J2
To check the required answer with in column K or W, we can use the Conditional Formatting > Highlight Cells Rules > Equal To... > key in "TRUE" > OK.
The answer is found to be 3 9 .
Is there no way to arrive to the result mathematically on pen and paper?
Log in to reply
Not that I know of. This is a Computer Science problem.
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 |
|
Turbo C++
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 |
|
@Calvin Lin @Ronak Agarwal please post a NT approach.
Log in to reply
There isn't really much to it other than trial and error.
I've moved this problem into CS, since that is the most sensible approach for problems like this.
I just realized that this comment wasn't true, so I edited it. It is now correct.
Log in to reply
You are absolutely basically I also wrote the problem with trial and error method as I do not know computer science much.I posted it here to know are there any number theory approach and thank you for moving it it's original section.
C++ solution
#include <bits/stdc++.h>
using namespace std;
int sumdigits(int n) {
int sm = 0;
while (n > 0) {
sm += n%10;
n/=10;
}
return sm;
}
int main () {
int i=0;
while (sumdigits(i) <= sumdigits(i*i)) i++;
cout << i << endl;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
VB.NET solution:
Module Module1
Sub Main()
For n = 1 To 1000
If the_sum(n) > the_sum(n * n) Then
Console.WriteLine(n)
Exit For
End If
Next
Console.ReadLine()
End Sub
Public Function the_sum(ByVal number As Integer) As Integer
Dim sum As Integer = 0
Dim a As String = number.ToString
For g = 1 To a.Length
sum = sum + Val(a(g - 1))
Next
Return sum
End Function
End Module
I found these families
3 9 3 9 9 3 9 9 9 ⋮ 3 9 0 3 9 9 0 3 9 9 9 0 ⋮ 3 9 0 0 3 9 9 0 0 3 9 9 9 0 0 ⋮ ⋯ ⋯ ⋯ ⋮
4 9 4 9 9 4 9 9 9 ⋮ 4 9 0 4 9 9 0 4 9 9 9 0 ⋮ 4 9 0 0 4 9 9 0 0 4 9 9 9 0 0 ⋮ ⋯ ⋯ ⋯ ⋮
numbers satisfy S ( x ) > S ( x 2 ) :
39 48 49 79 149 179 249 318 348 349 389 390 399 448 449 480 489 490 498 499 548 549 579 649 679 749 789 790 795 799 849 889 895 898 899 949
Problem Loading...
Note Loading...
Set Loading...
Python 2.7: