Yes, I know this legend. Attributed to Alexander the Great, among others...
You have to use double to get to square 64, this problem overflows type long.
public class RiceChessboard {
public static void main( String[] args ) {
double riceKerns = 1;
System.out.printf( "%2d %.0f%n", new Integer(1),riceKerns);
for (int i = 1; i < 64; i++) {
System.out.printf( "%2d %.0f%n", i+1,riceKerns *= 2);
}
}
}
// 64 -> 9,223,372,036,854,776,000
to show how big that is:
$ 1,000,000,000 -- a billion dollars would take just over 31 years to spend @ $1 per second