# [Mathematica] Number problem with digits

Tags:
1. Jun 21, 2014

Determine all three-digit number ,$N$, having the property that $N$ is divisible by 11, and $\frac{N}{11}$ is equal to the sum of the square of the digits of $N$.

This cannot be solved just by guessing. I think I should use mathematica for this,but, this sum of the digits is a scary thing. Does mathematica has a feature for that?

I know that
-$N$ is a multiple of 11.

Let the digits of $N$ be $a,b \text{ and } c$ respectively.
Now, $11(a^2+b^2+c^2)=abc$
I can't think of a way.

2. Jun 21, 2014

### D H

Staff Emeritus
Hint: You don't want $abc$. That's not $N$. That's the product of $a$, $b$, and $c$. You want something else, an expression that yields $N$ given $a$, $b$, and $c$.

3. Jun 21, 2014

Yes, that's what is confusing me. I really can't think of anything. The only expression I can think of is something like : $a,b,c$
Any hints?

$a$,$b$ and $c$ should be each less than 10.

4. Jun 21, 2014

### DrGreg

Well, think of an example, say $234$, two hundred and thirty four. What does the $2$ mean? What does the $3$ mean? It's not true that$$234 = 2 \times 3 \times 4$$. Can you think of another expression involving $2$, $3$, $4$, and some other numbers?

5. Jun 21, 2014

Hmm, What are you trying to imply here?
$2 \times 3 \times 4 =24$ but $2 \times 3 \times 3 \times 13 = 234$
I can't reproduce the number 234 by multiplying it's digits only. If I am to add division, subtraction,etc, then this will turn out to be impossible

6. Jun 21, 2014

### D H

Staff Emeritus
What does 234, two hundred and thirty four, mean? What mathematical magic lets us write that number as 234 (as opposed to CCXXXIV, or even worse, 234 tick marks)?

7. Jun 21, 2014

### Hepth

Like they're all trying to get you to ask yourself:

What does 234 mean. What number system is this. How could I possibly represent this number algebraically in terms of its digits. Why do we write it in this way? Why not 11101010? Why not EA?

Its MUCH easier than you realize, and because of this you might be over-thinking it.

Once you get to the programming part we can show you how to do the loop over all possible combinations of numerals, and how to check if it follows your rules.

8. Jun 22, 2014

The number system we use is based on the number 10.
When a digit increases to 10, then that digit will become 0 and +1 will be added to the digit on the left side.
So for example, if we have a number $10_40_30_20_1$ (I added sub numbers for explanation)
Numbers in the position $0_1$ are called ones, $0_2$ are called tens and so on.
If the digit $0_1$ increases to $10$, that digit will become 0 and to the digit next, on the left side($0_2$), a one will be added.

Hope you understand what I mean. Is this what you are asking for?

Last edited: Jun 22, 2014
9. Jun 22, 2014

### Staff: Mentor

Not sure what you mean, but you are finally mentioning things that are required to solve the problem. You are just still overthinking it.

10. Jun 22, 2014

I really don't understand what you are trying to say. I have mentioned everything I know about this numeral system.
Can you tell me exactly where I am over-thinking?

11. Jun 22, 2014

### Hepth

As this is not a homework forum ill just break the unspoken rule and ask if writing

4867 = 4*1000+8*100+6*10+7

12. Jun 22, 2014

Thank you so much! Why couldn't you say this earlier?

I will transform my previous equation to match with this.
$11(a^2+b^2+c^2)=(a \times 100)+(b \times 10)+(c \times 1)$
That means $11(a^2+b^2+c^2)=100a+10b+c$
Now I will have to do WHAT? Brute force?

13. Jun 22, 2014

### Hepth

Yes. Brute force is easiest if you only have 3 digits.

Did a table over If(LHS == RHS)
Then a*100+b*10+c
Else False
, for {a,0,9} ,{b,0,9}, {c,0,9}

Then I deletecases those that are false. I think there were very few cases.

14. Jun 22, 2014

P.S I am a beginner in programming( Self learning)

15. Jun 22, 2014

### Staff: Mentor

This is the very definition of the positional numeral system that you apparently know how to use. We all hoped you are just overthinking it and this equation is obvious to you.

16. Jun 22, 2014

I was never taught that. Anyway, I will keep that definition in my mind from now on.

17. Jun 22, 2014

### Staff: Mentor

So how do you know how much is 123?

18. Jun 22, 2014

It is 100+20+3
1 is the hundreds, 2 is the tens, and 3 is the ones.
So now with this new knowledge,it's $(100 \times 1)+(10 \times 2)+(1 \times 3)$

I think I knew the knowledge but didn't know how to apply it. There were taught in grade 1, more than 9 years ago.

Anyway, how will we proceed with this problem now?

19. Jun 22, 2014

### D H

Staff Emeritus
Even with homework problems there's a point where a bigger hint is acceptable, and sometimes even a big huge hint is OK. At this point, it's rather obvious that adjacent is struggling, so telling him what 4867 was entirely acceptable.

What 4867 means is very, very basic. Given that you are dabbling with a number theory problem here, we all expected that you would know what 4867 means.

This is a quadratic Diophantine problem in three variables. One simple solution is to ask Mathematica to solve $11(a^2+b^2+c^2) == 100 a + 10 b + c$ over the integers. That will give solutions such as a=0, b=0, c=0 and a=3,b=-1, c=-4 that you might want to exclude. You can exclude those with additional expressions to constrain a to the positive integers and b and c to the non-negative integers.

Suppose you want to try solving this without using Solve. One simple solution is to look at all 900 numbers of the form abc with 0<a≤9, 0≤b≤9, and 0≤c≤9. Learn to use Mathematica's list functions. That's extreme brute force, but with only 900 elements it's not going to take too long.

You can do much better than this. Your expression is the equation of a sphere. That expression can be rewritten as $(a - \frac{100}{22})^2 + (b - \frac{10}{22})^2 + (c-\frac{1}{22})^2 = \frac{10101}{484}$. That's a sphere with radius $r = \sqrt{10101}\,/22$ and center $(100/22, 10/22, 1/22)$. That means $(100-\sqrt{10101})/22 \le a \le (100+\sqrt{10101})$, $(10-\sqrt{10101})/22 \le b \le (10+\sqrt{10101})/22$, and $(1-\sqrt{10101})/22 \le c \le (1+\sqrt{10101})/22$. Since you are interested in integer values with $a>0$, $b,c \ge 0$, this means you only need to look at nine values for a, six for b, and five for c. That reduces the 900 (a,b,c) triples that need to be examined using the first brute force method to only 270 triples.

You can do much better than this. Clearing the denominator in the canonical spherical expression for this problem yields $(22a - 100)^2 + (22b-10)^2 + (22c-1)^2 = 10101$. Denoting $u=|22a-100|, v=|22b-10|, w=|22c-1|$, this can be written as $u^2+v^2+w^2=10101$. This is a sum of three squares problem! Ignoring permutations of (u,v,w) and changes in sign, there are only 20 values of (u,v,w) that satisfy $u^2+v^2+w^2=10101$. Filtering on the five possible values of w=|22c-1|=(1,21,43,65,87) for c=(0,1,2,3,4) yields just five (u,v,w) triples that need to be investigated, three for w=1 (c=0) and two for w=65 (c=3).

The Mathematica function PowersRepresentations give you the 20 integer solutions to $u^2+v^2+w^2=10101$. I'll leave filtering those to yield the desired solutions to your problem up to you.

Last edited: Jun 22, 2014
20. Jun 22, 2014

### D H

Staff Emeritus
Yes, you were taught this 9 years ago, but you have several years to go before you learn the deep magic behind this. That's something you'll learn in abstract algebra, a class you can take in college but only after taking the first three calculus classes.

Without having taken abstract algebra, you're more than a bit over your head trying to solve number theory problems.