Under construction

Still being built. Things may change

In or Out

Interview

Time limit2sMemory limit1024 MB

Summary
For each complex number c, iterate z = z^2 + c up to r times and report IN if |z| never exceeds 2, otherwise OUT.
Level

Easy3 of 10

Topics
Simulation, Math, Implementation
Solved
No attempts yet

Problem

Born in Warsaw, Benoît Mandelbrot (1924-2010) is considered the father of fractal geometry. He studied mathematical processes that described self-similar and natural shapes known as fractals. Perhaps his most well-known contribution is the Mandelbrot set, which is pictured below (the set contains the black points):

The Mandelbrot set is typically drawn on the complex plane, a 2-dimensional plane representing all complex numbers. The horizontal axis represents the real portion of the number, and the vertical axis represents the imaginary portion. A complex number c=x+yic = x + yi (at position (x,y)(x, y) on the complex plane) is not in the Mandelbrot set if the following sequence diverges:

zn+1←zn2+cz_{n+1} \leftarrow z_n^2 + c

beginning with z0=0z_0 = 0. That is, lim⁡n→∞∣zn∣=∞\lim_{n \to \infty}{|z_n|} = \infty. If the sequence does not diverge, then cc is in the set.

Recall the following facts about imaginary numbers and their arithmetic:

i=−1i = \sqrt{-1}, i2=−1i^2 = −1, (x+yi)2=x2−y2+2xyi(x + yi)^2 = x^2 − y^2 + 2xyi, ∣x+yi∣=x2+y2|x + yi| = \sqrt{x^2 + y^2}

where xx and yy are real numbers, and ∣⋅∣| \cdot | is known as the modulus of a complex number (in the complex plane, the modulus of x+yix + yi is equal to the straight-line distance from the origin to the the point (x,y)(x, y)).

Write a program which determines if the sequence znz_n diverges for a given value cc within a fixed number of iterations. That is, is cc in the Mandelbrot set or not? To detect divergence, just check to see if ∣zn∣>2|z_n| > 2 for any znz_n that we compute – if this happens, the sequence is guaranteed to diverge.

Input

Each test case is described by a single line containing three numbers: two real numbers −3≤x≤3-3 \le x \le 3 and −3≤y≤3-3 \le y \le 3, and an integer 0≤r≤10 0000 \le r \le 10\,000. The value of cc for this case is x+yix + yi, and rr is the maximum number of iterations to compute.

Output

For each case, display the case number followed by whether the given cc is in the Mandelbrot set, using IN or OUT.

Examples1

  1. Example 1

    Input
    0 0 100
    1.264 -1.109 100
    1.264 -1.109 10
    1.264 -1.109 1
    -2.914 -1.783 200
    0.124 0.369 200
    
    Expected output
    Case 1: IN
    Case 2: OUT
    Case 3: OUT
    Case 4: IN
    Case 5: OUT
    Case 6: IN