main :: IO () main = print $ length $ nub [a^n | a <- [2..100], n <- [2..100]]
Mathematica
1 2 3 4 5
(* * We generate all possible powers in the given range, put the values in a flat list, * delete the duplicates of any value, and count the length of the remaining list. *) Length[Union[Flatten[Table[a^b, {a, 2, 100}, {b, 2, 100}]]]]
publicfinalclassp029implementsEulerSolution{ publicstaticvoidmain(String[] args){ System.out.println(new p029().run()); } /* * We generate all the possible powers in the given range, put each value * into a set, and let the set count the number of unique values present. */ public String run(){ Set<BigInteger> generated = new HashSet<>(); for (int a = 2; a <= 100; a++) { for (int b = 2; b <= 100; b++) generated.add(BigInteger.valueOf(a).pow(b)); } return Integer.toString(generated.size()); } }