Problem 29: How many distinct terms are in the sequence generated by ab for 2 ≤ a ≤ 100 and 2 ≤ b ≤ 100?
import java.math.BigInteger;
import java.util.HashSet;
class runner
{
public static void main (String[] args) throws java.lang.Exception
{
long time = System.currentTimeMillis();
HashSet distinct = new HashSet();
for(int a=2;a<=100;a++){
for(int b=2;b<=100;b++){
BigInteger prod = new BigInteger(""+a);
distinct.add(prod.pow(b));
}
}
System.out.println(distinct.size());
System.out.println("time:"+(System.currentTimeMillis()-time));
}
}