How many 3-digit numbers satisfy:
a b c = a 3 + b 3 + c 3
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.
000 and 001 not inclusive.
Log in to reply
I'm not clear about what you mean. Notice that the loop involving s goes from 100 through 999 inclusive.
Log in to reply
Very often I see that the front digit(s) of zero(es) is (are) not inclusive in brilliant. Just like to take note of these.
Log in to reply
@Lu Chee Ket – Yes, it would have been easy to have made that mistake.
Log in to reply
@Bill Bell – Not a mistake to me but whether how we like to take.
My python solution:
l = []
for i in range(100, 1000):
m = str(i)
if i == (int(m[0])**3 + int(m[1])**3 + int(m[2])**3):
l.append(i)
len(l)
Result: 4
1 2 3 4 5 6 |
|
Python:
1 2 3 4 5 6 |
|
An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits.
Armstrong numbers of order three is 153, 370. 371, 407 respectively.
(An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself)
Hence the solution is 4.
I used 'BASIC'
10 for n=100 to 999
20 n$=str$(n)
30 a=val(left$(n$,1))
40 b=val(mid$(n$,2,1))
50 c=val(right$(n$,1))
60 if a^3+b^3+c^3=n then cnt=cnt+1:print n,cnt
70 next n
80 print "Done !!"
OUTPUT
153 1
370 2
371 3
407 4
Done !!
This program would run on many 8-bit computers from the '70's and '80's Apple II,+,e,c Commodore PET, VIC20, C64 (I have all of them in my museum) It runs on my PC, as is, using " Just Basic " but it doesn't need line numbers.
Since there are finitely many cases, we could check every single case and arrive at the answer.
My Solution in C++
using namespace std;
int main()
{
int cnt=0;
for(int i=100; i<1000; i++)
{
int a=i;
int c=a%10;
a/=10;
int b=a%10;
a/=10;
if(i==(a*a*a + b*b*b + c*c*c))
cnt++;
}
cout<<cnt<<endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
I used C++ too
1 2 3 4 5 6 7 8 9 |
|
My idea is that the n t h digit of a number, i, is given by ( i% 1 0 n ) / 1 0 n − 1
1 2 3 4 5 6 7 |
|
Problem Loading...
Note Loading...
Set Loading...
Let me explain this logically.
We note that the RHS can only come from the sum of three cubes, which are:
0 3 = 0 5 3 = 1 2 5 1 3 = 1 6 3 = 2 1 6 2 3 = 8 7 3 = 3 4 3 3 3 = 2 7 8 3 = 5 1 2 4 3 = 6 4 9 3 = 7 2 9
If a = 1 ⇒ 1 0 0 < RHS < 2 0 0 and the possible solutions are:
1 0 5 = 1 + 0 + 1 2 5 = 1 2 6
1 1 5 = 1 + 1 + 1 2 5 = 1 2 7
1 2 5 = 1 + 8 + 1 2 5 = 1 3 4
1 3 5 = 1 + 2 7 + 1 2 5 = 1 5 3
1 4 4 = 1 + 6 4 + 6 4 = 1 2 9
1 5 0 = 1 + 1 2 5 + 0 = 1 2 6
1 5 1 = 1 + 1 2 5 + 1 = 1 2 7
1 5 2 = 1 + 1 2 5 + 8 = 1 3 4
1 5 3 = 1 + 1 2 5 + 2 7 = 1 5 3 ← acceptable solution
1 5 4 = 1 + 1 2 5 + 6 4 = 1 9 0
Similarly, the other solutions are: 3 7 0 , 3 7 1 and 4 0 7 .