Problem
This problem comes from Project Euler 29
Problem
Consider all integer combinations of for and :
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125.
How many distinct terms are in the sequence generated by for and ?
Solution
I decided to go with the most straight-forward solution.
- For and , calculate
- Put the result into a
set, so that it automatically removes duplicates - Print the length of the
set
Code
# Project Euler: Problem 29
# Distinct Powers
ab = set()
for a in range(2, 101):
for b in range(2, 101):
ab.add(a**b)
print(len(ab))