If a square number (a^2) ends with xyxyxyxyxy, then xy should be one of 21, 29, 61, 69, 84, [Inspired by this Fermat’s Library LinkedIn post]
To prove this, we first write a = 5*10^9n+k
Now, a^2 = 25*10^{18}n^2 + 10^{10}nk + k^2
Hence, the last 10 digits are determined by the last 10 digits of k^2, 0 \leq k < 5*10^9. Although it is possible to find via a more efficient DFS search, for simplicity, we can kick off a brute force search utilizing a big number library (in Node.js).
const Big = require('big.js');
let s = new Set()
for (let i = 0; i < 5e9; i++) {
if (i % 1000000 == 0) { console.log( ' ---- ' + i)}
let p = new Big(i)
let j = p.times(p).toString()
let last = j.substr(-2, 2)
let isRepeat = true
for (let k = 1; k < 5; k++) {
let next = j.substr(-2 - 2*k, 2)
if (last != next) {
isRepeat = false
break
}
}
if (last != '00' && isRepeat) {
console.log(i, j, last)
s.add(last)
}
}
console.log(s)
This code took about a couple of hours to run on a MacBook Pro. It found all numbers of this form and it is proved.
First Occurrences of Different xy Endings
xy | a | a^2 |
21 | 508853989 | 258932382121212121 |
29 | 162459327 | 26393032929292929 |
61 | 1318820881 | 1739288516161616161 |
69 | 541713187 | 293453176969696969 |
84 | 509895478 | 259993398484848484 |