Project Euler 206: Find the unique positive integer for a concealed square
Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.
The square of any number, n, will end in 00 if the last digit of n is zero. So, our square root ends in a zero and the square has the form 1_2_3_4_5_6_7_8_900.
We can reduce our search to 1_2_3_4_5_6_7_8_9 and multiply the square root (when we find it) by 10. Now, the only way to end a square with 9 is to square a number ending with 3 or 7. OK, so our square root ends with 3 or 7, an odd number, and we can skip even-numbered n from consideration.
Let’s begin our search with the maximum possible number, 19293949596979899 and take its square root. Starting with an odd number we count down by 2 until the square fits our pattern.
Project Euler 206 SolutionRuns < 0.001 seconds in Python 2.7.
Use this link to get the Project Euler 206 Solution Python 2.7 source.
AnswerSlowly swipe from either end beginning with the white vertical bar to get an idea of the starting or ending digits. For less drama, just double click the answer area. The distance between the two bars will give you an idea of the magnitude. Touch devices can tap and hold the center of the box between the two bars and choose define to reveal the answer.
- The square root can only be a 9 digit integer that starts with 1 and ends with 0.