title: Fast way to find a unhappy number
body: <p>I'm trying to solve a question. Given a range of integers user has to find the number of unhappy present in the given range.</p>
  
  <p><a href="https://en.wikipedia.org/wiki/Happy_number#Unhappy_number" rel="nofollow">Unhappy number</a>- a number n such that iterating this sum-of-squared-digits map starting with n never reaches the number 1. </p>
  
  <p>I've tried using the brute force approach by calculating the sum of the squares of digits and if at any instant it is equal to any of these (4, 16, 37, 58, 89, 145, 42, 20) then it is a unhappy number.</p>
  
  <p>This approach is giving TLE is there any better method?? </p>
  
  <p>Range is between 1 to 10^18.</p>