Сам код:
x = 9 ** 81 + 27 ** 729 - 4
s = ''
while x:
s = str(x % 9) + s
x //= 9
m = max(list(s))
s = s.replace('0', m)
print(s.count(m))