Euler 0029
The Problem:
How many distinct terms are in the sequence generated by a^b for a and b being bounded to 2 and 100 inclusive?
Considerations and Approach:
Naively, this is only processing 100*100 numbers, not really much at all.
We can create a python set and then insert every calculation, so it will remove the redundancy.
The Code:
lower_limit = 2
upper_limit = 100
#create a set
distinct = set()
#go through the inclusive ranges
for i in range(lower_limit, upper_limit + 1):
for j in range(lower_limit, upper_limit + 1):
#do the set addition operator for a^b
distinct.add(i**j)
#print how many distinct pairs that we created
print(len(distinct))
No comments to display
No comments to display