sequence with sum of digits

Let s ( n ) s(n) denotes the sum of the digits of the positive integer n n . For example, s ( 521 ) = 5 + 2 + 1 = 8 s(521)=5+2+1=8 .

Define a sequence { a n } \{a_n\} where a 1 = 521 a_1=521 and a k + 1 = a k + s ( a k ) a_{k+1}=a_k+s(a_k) for each k 1 k\ge 1 . Find the smallest value of a m a_m for which a m > 1000 a_m>1000 .


The answer is 1003.

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.

2 solutions

Kyle T
Mar 12, 2019

<?php
$arr = array(521); //start with 521 as stated in question
do {
$a = $arr[count($arr)-1]; // get last value in array
$s = array_sum(str_split($a)); // sum of digits
$arr[] = $a+$s; //enter new value into sequence
} while($arr[count($arr)-1]<1000); //stop when we find a number > 1000
//print the answer
echo $arr[count($arr)-1].'<br>'; // 1003
//print the whole sequence
echo '<pre>'.print_r($arr,true).'</pre>'; // (see Joshua's answer for entire sequence)
?>


Joshua Lowrance
Mar 9, 2019

{ 521 , 529 , 545 , 559 , 578 , 598 , 620 , 628 , 644 , 658 , 677 , 697 , 719 , 738 , 752 , 766 , 785 , 805 , 818 , 835 , 851 , 865 , 884 , 904 , 917 , 934 , 950 , 964 , 983 , 1003 } \{521,529,545,559,578,598,620,628,644,658,677,697,719,738,752,766,785,805,818,835,851,865,884,904,917,934,950,964,983,1003\cdots \} . The first number over 1000 1000 is 1003 1003 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...