Find the sum of the digits of the 889th smallest positive integer whose square ends in 889.
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.
@Otto Bretscher , we really liked your comment, and have converted it into a solution. If you subscribe to this solution, you will receive notifications about future comments.
Just for the sake of curiosity, by extending Steven Yuan 's solution we obtain a formula for the n 'th positive integer whose square ends in 8 8 9 . Let us call such a number an 889-number.
We have that { 5 0 i + 3 3 } i = 0 ∞ is a sequence of numbers whose respective squares end in 89, and further that if i = 1 + 5 j , the respective squares end in 8 8 9 . That is, for a non-negative integer j , the square of s 1 ( j ) = 2 5 0 j + 8 3 ends in 8 8 9 .
Similarly for numbers { 1 0 i + 7 } i = 0 ∞ , we conclude that for a non-negative integer j , the square of s 2 ( j ) = 2 5 0 j + 1 6 7 ends in 8 8 9 .
Notice that s 1 ( j ) < s 2 ( j ) < s 1 ( j + 1 ) < s 2 ( j + 1 ) for j ≥ 0 . So to get the k 'th 889-number, we compute s 1 ( 2 k − 1 ) if k is odd; otherwise we compute s 2 ( 2 k − 1 ) .
Hence, the n 'th 889-number can be computed as N 8 8 9 ( n ) = { 1 2 5 n − 4 2 1 2 5 n − 8 3 if n is odd if n is even
(Edit by me: Simplified formula by @Otto Bretscher )
Otto Bretscher mentions in a comment further below that we can express N in a single line: N 8 8 9 ( n ) = 2 1 2 5 ( 2 n − 1 ) − 4 1 ( − 1 ) n
@Martin Sergio H. Faester , we really liked your comment, and have converted it into a solution. If you subscribe to this solution, you will receive notifications about future comments.
I don't have time for a full solution yet, so here's a general outline:
Let a be our desired integer. We know that a must end with 3 or 7 . Thus, a is of the form 1 0 n + 3 or 1 0 n + 7 , for some positive integer n . So, we have two cases:
Case 1: The number is of the form 1 0 n + 3
Squaring and taking m o d 1 0 0 yields n ≡ 3 ( m o d 5 ) , or n = 5 m + 3 for some positive integer m . Plug this back into our squared expression and taking m o d 1 0 0 0 yields m ≡ 1 ( m o d 1 0 ) or m ≡ 6 ( m o d 1 0 ) . Thus, n = 8 , 3 3 , 8 3 , ⋯ .
Case 2: The number is of the form 1 0 n + 7
Following the same steps as Case 1 yields n = 5 m + 1 and m ≡ 3 ( m o d 1 0 ) or 8 ( m o d 1 0 ) . Thus, n = 1 6 , 4 1 , 6 6 , ⋯ .
Our first few values for a are
8 3 , 1 6 7 , 3 3 3 , 4 1 7 , 5 8 3 , 6 6 7 , 8 3 3 , 9 1 7 , ⋯ .
The rest of the integers in this sequence just append digits in front of the eight smallest solutions e.g. 7 2 8 3 3 , 3 1 4 1 5 9 2 6 9 1 7 , and they repeat in chunks of eight. Since 8 8 9 ≡ 1 ( m o d 8 ) , a will end in 0 8 3 . Since ⌊ 8 8 8 9 ⌋ = 1 1 1 , the integers appended are 1 1 1 . Thus, a = 1 1 1 0 8 3 , which has digit sum 1 4 .
Just for the sake of curiosity, by extending Steven Yuan 's solution we obtain a formula for the n 'th positive integer whose square ends in 8 8 9 . Let us call such a number an 889-number.
We have that { 5 0 i + 3 3 } i = 0 ∞ is a sequence of numbers whose respective squares end in 89, and further that if i = 1 + 5 j , the respective squares end in 8 8 9 . That is, for a non-negative integer j , the square of s 1 ( j ) = 2 5 0 j + 8 3 ends in 8 8 9 .
Similarly for numbers { 1 0 i + 7 } i = 0 ∞ , we conclude that for a non-negative integer j , the square of s 2 ( j ) = 2 5 0 j + 1 6 7 ends in 8 8 9 .
Notice that s 1 ( j ) < s 2 ( j ) < s 1 ( j + 1 ) < s 2 ( j + 1 ) for j ≥ 0 . So to get the k 'th 889-number, we compute s 1 ( 2 k − 1 ) if k is odd; otherwise we compute s 2 ( 2 k − 1 ) .
Hence, the n 'th 889-number can be computed as N 8 8 9 ( n ) = { 1 2 5 n − 4 2 1 2 5 n − 8 3 if n is odd if n is even
Log in to reply
We can even write a single formula, N ( n ) = 2 1 2 5 ( 2 n − 1 ) − 4 1 ( − 1 ) n
Your solution would be much clearer if you applied the Chinese Remainder Theorem directly, to explain why the numbers must be of the form that you stated.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Python 2.7:
1 2 3 4 5 6 7 |
|
I did it little differently, though.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Log in to reply
I always like to define functions so that I can use them in future also whenever possible and they look nicer as well.
Yeah, this problem can be killed with a simple script, but the "real" solution requires just number theory. ⌣ ¨
Log in to reply
Yeah, I know. :|
I usually pick the lame option and kill problems with scripts, but I definitely want to learn how to do it though. If you have some good resources on number theory I'd like to see them.
Problem Loading...
Note Loading...
Set Loading...
We can streamline Steven's excellent approach a bit. My solution will be based on the observation that x 2 ends in ... 889 if and only if x 2 − 8 8 9 is divisible by both 125 and 8. Now x 2 − 8 8 9 is divisible by 8 for all odd numbers x , since x 2 ≡ 1 ≡ 8 8 9 ( m o d 8 ) for odd x . The real issue is the divisibility by 125. Let's find the solutions of x 2 ≡ 8 8 9 ≡ 1 4 ( m o d 1 2 5 ) . Working our way up, we see that the solutions of x 2 ≡ 8 8 9 ≡ 4 ( m o d 5 ) are 2 and 5 − 2 = 3 , and the solutions of x 2 ≡ 8 8 9 ≡ 1 4 ( m o d 2 5 ) are 8 and 2 5 − 8 = 1 7 ; we only need to check 2, 7, 12, 3 and 8 here. Finally, the solutions of x 2 ≡ 8 8 9 ≡ 1 4 ( m o d 1 2 5 ) are 42 and 1 2 5 − 4 2 = 8 3 (again, we only need to check 5 candidates). Thus every interval [ 1 2 5 ( n − 1 ) , 1 2 5 n ] contains exactly two x with x 2 ≡ 8 8 9 ≡ 1 4 ( m o d 1 2 5 ) , an even and an odd number. (As Martin observes, these two numbers are 1 2 5 n − 8 3 and 1 2 5 n − 4 2 ). If such a number x is odd, then x 2 will end in ...889, as we observed earlier. The 889th such number is 1 2 5 × 8 8 9 − 4 2 = 1 2 5 × 8 8 8 + 8 3 = 1 1 1 0 8 3 .