37 lines
886 B
Python
37 lines
886 B
Python
'''
|
|
A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.
|
|
|
|
Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?
|
|
'''
|
|
|
|
import time
|
|
import math
|
|
|
|
def intSum(n):
|
|
res = 0
|
|
while n > 0:
|
|
res += n % 10
|
|
n //= 10
|
|
|
|
return res
|
|
|
|
def main():
|
|
print("Hello, this is Patrick")
|
|
t0 = time.time()
|
|
|
|
maxSum = 0
|
|
|
|
for a in range(100):
|
|
if a % 10 == 0:
|
|
continue
|
|
for b in range(100):
|
|
if b % 10 == 0:
|
|
continue
|
|
|
|
if intSum(a**b) > maxSum:
|
|
maxSum = intSum(a**b)
|
|
|
|
print(maxSum, time.time() - t0)
|
|
|
|
if __name__ == "__main__":
|
|
main() |