def fiter(a, finit, fcntn, ftrns): x = finit(a) while fcntn(a, x): x = ftrns(a, x) return x def newton_root(a): return fiter(a, lambda x: x // 2, lambda p, x: not (0 < p - x ** 2 < 2 * x + 1), lambda p, x: (x + p // x) // 2) def all_root(limit, digit): root_sum = [] digit -= 1 for x in range(2, limit + 1): if int(x ** 0.5) ** 2 != x: root_sum.append(sum(map(lambda x: int(x), str(newton_root(100 ** digit * x))))) return root_sum print(sum(all_root(100, 100)))