There exists at least one number that is 6 times the sum of its digits. What is the first occurrence of this phenomenon and are there any other numbers with this same pattern? For bonus points write a program to solve this problem.
There exists at least one number that is 6 times the sum of its digits. What is the first occurrence of this phenomenon and are there any other numbers with this same pattern? For bonus points write a program to solve this problem.
Permalink: http://problemotd.com/problem/six-times/
Content curated by @MaxBurstein
Comments:
parth - 10 years, 3 months ago
54
only one number.
js:
for (var i=10;i<10000000;i++){ if ( sumOfDigits(i)*6 == i ){ console.log(i); } }
function sumOfDigits(d){ d = parseInt(d); var sum = 0; while (d > 0){ sum += d%10; d = parseInt(d/10); } return sum; }
reply permalink
Anonymous - 10 years, 3 months ago
0 is the first, 54 is the second
reply permalink
Anonymous - 10 years, 3 months ago
There are two such numbers : 0 and 54
Negative and non-integer numbers are ruled out by the fact that the sum of the digits of a number is always a positive integer.
So we are left with positive integers, for which we should solve the following indetermined sum (a[i] is the i-th digit of a (starting at i=0), and n is the number of digits of a):
0 == \sum_{i = 0}^{n-1} (6 - 10i) * a[i]
Note that for i=0, (6 - 10i) = 5, which is the only positive term.
The next one is -4.
Then, we are left with numbers < -90. Since 0 <= a[i] <= 9, those cannot be compensated by the first (positive) term (since 9*5 = 45).
So the only possibilities are 0 and 54.
reply permalink
wobblebucket - 10 years, 3 months ago
reply permalink
btgrant-76 - 10 years, 3 months ago
A little Scala. No state mutations and
par
produces a parallel collection.reply permalink
asheehan - 10 years, 2 months ago
thought I submitted one for this, but don't see it here. Hmmm... Here's my program in Ruby:
reply permalink