public static void main ( String [] args ) {
	BigInteger iBig = new BigInteger("1");
	BigInteger one = new BigInteger("1");
	BigInteger thousand = new BigInteger("1000");
	BigInteger sum = new BigInteger("0");
	BigInteger product = new BigInteger("1");
	int i = 1;
	String s = "";

	while ( iBig.compareTo(thousand)==-1 && i<1001 ) {
	    product = iBig.pow(i);
	    sum = sum.add(product);
	    i++;
	    iBig = iBig.add(one);
	}
	s = sum.toString();
	System.out.println("last ten digits = "+s.substring(s.length()-10));

    }