# E-2 MCS 260 Fri 11 July 2014 : third question on part two of midterm
"""
Use list comprehensions to solve the following problem:

Find all natural numbers less than or equal than 1,000,000
that have their square and cube root both as a natural number.

For example 1,000,000 = 10^6, its square root is 10^(6/2) = 10^3 = 1,000
and its cube root is 10^(6/3) = 10^2 = 100.
Thus 1,000,000 has natural square and cube roots.
So does 64: 64 = 2^6 = 4^3 = 8^2, as 4 = 2^(6/3) and 8 = 2^(6/2).

The algorithm runs as follows:
(1) make a list of all natural numbers from 0 to 1000, 1000 included;
(2) compute the list of all squares of this list of 1001 numbers;
(3) compute the list of all cubes of this list of 1001 numbers;
(4) take from the list of squares those that are also in the cubes.
"""
r = range(1001)
squares = [x**2 for x in r]
cubes = [x**3 for x in r]
f = filter(lambda x: x in cubes, squares)
a = [round(x**(1.0/3)) for x in f]
b = [round(x**(1.0/2)) for x in f]
print f
