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

xyaa^2
21508853989258932382121212121
2916245932726393032929292929
6113188208811739288516161616161
69541713187293453176969696969
84509895478259993398484848484
.

Leave a Reply

Your email address will not be published. Required fields are marked *