import java.math.BigInteger; import java.io.*; //after this is run, the output of each is written to prob29data.txt. //it becomes a simple operation to then (sort -n prob29data.txt | uniq | wc -l) in linux public class prob29 { public static void main(String args[]) { int i, j; BigInteger r; try{ FileWriter fstream = new FileWriter("prob29data.txt"); BufferedWriter out = new BufferedWriter(fstream); for (i = 2; i <= 100; i++) { for (j = 2; j <= 100; j++) { r = new BigInteger("" + i); r = r.pow(j); out.write(r.toString() + "\n"); } } out.close(); } catch (Exception e) { System.err.println("Error"); } } }