// User: msk

public class Main {
    static final int RESOLUTION =5000;
    static class Test1 {
        static int iters(int max_iter,double xc,double yc) {
           double x = xc;
           double y = yc;
           for(int count = 0;count<max_iter;count++) {
              if( x*x + y*y >= 4.0) { return count; }
              double tmp = x*x-y*y+xc;
              y = 2.0 * x * y + yc;
              x = tmp;
           }
           return max_iter;
        }


        static void run() {
            final long st = System.currentTimeMillis();
           int    max_val = RESOLUTION/2;
           int    min_val = -max_val;
           double mul = 2.0 / max_val;
           int    count = 0;
           for(int i=min_val;i<=max_val;i++)
           for(int j=min_val;j<=max_val;j++)
             count += iters(100,mul*i,mul*j);
            System.out.println("result: " + count);
            final long en = System.currentTimeMillis();
            System.out.println("Time=%g" + ((double) (en - st) / 1000.0));
        }
    }

//-----------------------------------------------------------------

    static class Test2 {
        static class Complex {
            double x, y;
            public Complex(double xc,double yc) { x = xc; y = yc; }
            double norm_square() { return x * x + y *y; }

            Complex mul (Complex  other) {
             return new Complex(x*other.x-y*other.y, x * other.y + y * other.x);
            }

            Complex add(Complex other) {
              return new Complex(x + other.x, y + other.y);
            }
        }

        static int iters(int max_iter,double xc,double yc) {
          Complex c = new Complex(xc,yc);
          Complex z = new Complex(xc,yc);
           for(int count = 0;count<max_iter;count++) {
              if( z.norm_square() >= 4.0 ) { return count; }
              z = z.mul (z).add (c);
           }

           return max_iter;
        }


        static void run() {
            final long st = System.currentTimeMillis();
           int    max_val = RESOLUTION/2;
           int    min_val = -max_val;
           double mul = 2.0 / max_val;
           int    count = 0;
           for(int i=min_val;i<=max_val;i++)
           for(int j=min_val;j<=max_val;j++)
             count += iters(100,mul*i,mul*j);
            System.out.println("result: " + count);
            final long en = System.currentTimeMillis();
            System.out.println("Time=%g" + ((double) (en - st) / 1000.0));
        }
    }

    public static void main(String[] args) {
        Test1.run ();
        Test2.run ();
    }
}

