'''simple docstring'''
_A		:      List[str]						   ={
    '''0''': 1,
    '''1''': 1,
    '''2''': 2,
    '''3''': 6,
    '''4''': 2_4,
    '''5''': 1_2_0,
    '''6''': 7_2_0,
    '''7''': 5_0_4_0,
    '''8''': 4_0_3_2_0,
    '''9''': 3_6_2_8_8_0,
}

_A		:      Union[str, Any]						   ={1_4_5: 1_4_5}

_A		:      Dict						   ={
    1_4_5: 0,
    1_6_9: 3,
    3_6_3_0_1: 3,
    1_4_5_4: 3,
    8_7_1: 2,
    4_5_3_6_1: 2,
    8_7_2: 2,
}







def 				__UpperCamelCase (					__UpperCAmelCase  :					int			)							->	int:
  if n in CACHE_SUM_DIGIT_FACTORIALS:
    return CACHE_SUM_DIGIT_FACTORIALS[n]
  lowercase				:							Tuple									=   sum(DIGIT_FACTORIALS[let] for let in str(__UpperCAmelCase			)			)
  lowercase				:							Optional[Any]									=   ret
  return ret







def 				__UpperCamelCase (					__UpperCAmelCase  :					int ,   __UpperCAmelCase  :					set | None = None			)							->	int:
  lowercase				:							Union[str, Any]									=   previous or set()
  if n in CHAIN_LENGTH_CACHE:
    return CHAIN_LENGTH_CACHE[n]
  lowercase				:							str									=   sum_digit_factorials(__UpperCAmelCase			)
  if next_number in previous:
    lowercase				:							int									=   0
    return 0
  else:
    previous.add(__UpperCAmelCase			)
    lowercase				:							Optional[int]									=   1 + chain_length(__UpperCAmelCase ,   __UpperCAmelCase			)
    lowercase				:							Union[str, Any]									=   ret
    return ret







def 				__UpperCamelCase (					__UpperCAmelCase  :					int = 60 ,   __UpperCAmelCase  :					int = 1_000_000			)							->	int:
  return sum(1 for i in range(1 ,   __UpperCAmelCase			) if chain_length(__UpperCAmelCase			) == num_terms			)


if __name__ == "__main__":
 print(f"""{solution() = }""")
'''simple docstring'''
from __future__ import annotations

import math
import random







def 				__UpperCamelCase (					__UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int ,   __UpperCAmelCase  :					int			)							->	list[int]:
  lowercase				:							Union[str, Any]									=   d * e - 1
  lowercase				:							List[str]									=   0
  lowercase				:							Tuple									=   0
  while p == 0:
    lowercase				:							Optional[Any]									=   random.randint(2 ,   n - 1			)
    lowercase				:							Dict									=   k
    while True:
      if t % 2 == 0:
        lowercase				:							List[Any]									=   t // 2
        lowercase				:							Union[str, Any]									=   (g**t) % n
        lowercase				:							Optional[Any]									=   math.gcd(x - 1 ,   __UpperCAmelCase			)
        if x > 1 and y > 1:
          lowercase				:							Dict									=   y
          lowercase				:							Any									=   n // y
          break  # find the correct factors
      else:
        break  # t is not divisible by 2, break and choose another g
  return sorted([p, q]			)


if __name__ == "__main__":
 import doctest

 doctest.testmod()