
"""simple docstring"""





_a		       =							[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(100_000)]







def 	__a     (		__lowerCamelCase  ):
   UpperCAmelCase_					:					Optional[Any]			     =    0
   while number:
      # Increased Speed Slightly by checking every 5 digits together.
      sum_of_digits_squared += DIGITS_SQUARED[number % 10_0000]
      number //= 10_0000

   return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
_a		       =							[None] * 10_000_000
_a		       =							True
_a		       =							False







def 	__a     (		__lowerCamelCase  ):

   if CHAINS[number - 1] is not None:
      return CHAINS[number - 1]  # type: ignore

   UpperCAmelCase_					:					List[Any]			     =    chain(next_number(__lowerCamelCase  )  )
   UpperCAmelCase_					:					List[Any]			     =    number_chain

   while number < 1000_0000:
      UpperCAmelCase_					:					Dict			     =    number_chain
      number *= 10

   return number_chain







def 	__a     (		__lowerCamelCase = 1000_0000  ):
   for i in range(1,		__lowerCamelCase  ):
      if CHAINS[i] is None:
         chain(i + 1  )

   return CHAINS[:number].count(__lowerCamelCase  )


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    print(f"""{solution() = }""")




"""simple docstring"""





def 	__a     (		__lowerCamelCase = 3,		__lowerCamelCase = 7,		__lowerCamelCase = 100_0000  ):
   UpperCAmelCase_					:					Dict			     =    0
   UpperCAmelCase_					:					List[Any]			     =    1

   for current_denominator in range(1,		limit + 1  ):
      UpperCAmelCase_					:					Dict			     =    current_denominator * numerator // denominator
      if current_denominator % denominator == 0:
         current_numerator -= 1
      if current_numerator * max_denominator > current_denominator * max_numerator:
         UpperCAmelCase_					:					List[Any]			     =    current_numerator
         UpperCAmelCase_					:					Optional[int]			     =    current_denominator
   return max_numerator


if __name__ == "__main__":
    print(solution(numerator=3, denominator=7, limit=1_000_000))


