In or Out
InterviewTime limit2sMemory limit1024 MB
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 (at position on the complex plane) is not in the Mandelbrot set if the following sequence diverges:
beginning with . That is, . If the sequence does not diverge, then is in the set.
Recall the following facts about imaginary numbers and their arithmetic:
, , ,
where and are real numbers, and is known as the modulus of a complex number (in the complex plane, the modulus of is equal to the straight-line distance from the origin to the the point ).
Write a program which determines if the sequence diverges for a given value within a fixed number of iterations. That is, is in the Mandelbrot set or not? To detect divergence, just check to see if for any 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 and , and an integer . The value of for this case is , and is the maximum number of iterations to compute.
Output
For each case, display the case number followed by whether the given is in the Mandelbrot set, using IN or OUT.