A 6-digit positive integer N is squared to form a 12-digit number. The center six digits of N^2 constitute N. Determine all possible values of N.
(If 'abcdef' was the 6-digit number, then the 12-digit number would look like 'uvwabcdefxyz'.)
Will there be any further solution(s) if N contained a leading zero?
Method One: analytic assist
6-digit number is N
12-digit number is the concatenation ANB where A and B are 3-digit numbers
N^2 = A*10^9 + 1000N + B
N^2 - 1000N - (A*10^9 + B) = 0
N = 500 ± [sqrt (10^6 + 4*A*10^9 + 4B)]/2
N = 500 ± [sqrt (250000 + A*10^9 + B)]
reject the - option because then N<0
N = 500 + sqrt (250000 + A*10^9 + B)
The first method goes through all possible values of A and B, calculates N from Pythagorean theorem then checks if first 3 and last 3 characters of N^2 are A and B. With these constraints, rejecting non integer values of N was not necessary.
There are four solutions, letting n have leading zeros did not add any:
A B N N^2
0 0 1000 1000000 rejected; N^2 not a 12 digit number
141 0 376000 141376000000
245 625 495475 245495475625
390 0 625000 390625000000
943 724 971582 943971582724
Method Two:
Make a list of all 12 digit squares; check if middle 6 squared is the same
Output of second program:
376000 141376000000
495475 245495475625
625000 390625000000
971582 943971582724
-----------
for a in range(1000):
for b in range(1000):
n = 500 + (250000 + a*10**9 + b)**.5
# if n%1 != 0:
# continue
nsqr = n*n
if nsqr%1000 != b or int(nsqr/10**9) != a:
continue
print(a,b,int(n), int(n**2))
squares = [i*i for i in range(316228, 1000000)]
for s in squares:
n = int(str(s)[3:9])
if n*n == s:
print(n,s)
|
Posted by Larry
on 2023-07-15 07:57:26 |