#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return bool布尔型
#
class Solution:
    def happynum(self, n: int) -> bool:
        # write code here
        s = n
        while True:
            if (s == 1) + (s == 7):
                return True
            if s // 10 == 0:
                return False
            s = sum(map(lambda x: int(x) ** 2, str(s)))