Project Euler – Problem 63

Problem 63:
The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the 9-digit number, 134217728=8^9, is a ninth power.

How many n-digit positive integers exist which are also an nth power?

package runner;

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 store = new HashSet(); 
		int power=1;

		boolean found = true;
		while(found){
			found = false;
			BigInteger base = BigInteger.ONE;
			do{
				BigInteger r = base.pow(power);
				if(r.toString().length() > power) break;
				if(r.toString().length() == power){
					store.add(r.toString());
					found = true;
				}
				base = base.add(BigInteger.ONE);
			}while(true);
			power++;
		}
		System.out.println(store.size());
		System.out.println("time:"+(System.currentTimeMillis()-time));
	}
}