// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class CubicRoot {
   public static int cubroot(int n) {
      int guess = 1;
      do {
         int newguess = guess - ((guess * guess * guess - n) / (3 * guess * guess));
         guess =  (newguess != guess) ? newguess : newguess + (Math.random() > 0.5 ? 1 : -1);
         if (guess > 1290)  guess = 1290;
         if (guess <= 0) guess = 1;
      } while ((n < guess * guess * guess) || (n >= (guess + 1) * (guess + 1) * (guess + 1)));
      return guess;
   }
   public static void main(String[] args) {
      for (int i = 1; i <= 100; i++) {
         int j = cubroot(i);
         System.out.println((j * j * j) + " <= " + i + " < " + (j + 1) * (j + 1) * (j + 1));
      }
      for (int i = 1; i <= 1000000; i++) {
         int j = cubroot(i);
      }
   }
}
