title: When does `n` match last digits of `n^2`?
body: <p>I'm solving one programming problem.</p>
  
  <blockquote>
    <p>Find all numbers <code>x</code> from <code>1</code> to <code>n</code> that have a property that digits
    of <code>x</code> match digits at the end of <code>x^2</code>.</p>
  </blockquote>
  
  <p>For example:</p>
  
  <pre><code>5 matches last digit of 5^2 (25)
  6 matches last digit of 6^2 (36)
  25 matches last digits of 25^2 (625)
  76 matches last digits of 76^2 (5776)
  376 matches last digits of 376^2 (141376)
  625 matches last digits of 625^2 (390625)
  etc.
  </code></pre>
  
  <p>Does anyone know what the numerical criteria is for a number to match itself in last digits of it squared?</p>
  
  <p>I'm programming this in Python and I can only use numeric operations such as <code>/</code>, <code>%</code>, <code>//</code>, <code>*</code>, <code>+</code>, etc.</p>
  
  <p>I can't use <code>str</code> or <code>len</code> or string functions to slice numbers.</p>