see this sequences have 2 extrapolation, so the formula is :
f(n) = a*n^2 + b*n + c
n = 1 -> a + b + c = 2 ...1)
n = 2 -> 4a + 2b + c = 4 ...2)
n = 3 -> 9a + 3b + c = 8 ...3)
solve it you will get a = 1, b = -1, and c = 2;
so the equation is:
f(n) = n^2 - n + 2.
Any comment about algorithm you have used? Why just posting the code without any comment? It would be much easier to help you if you would describe your algorithm instead of posting just the code.
Here's a way to derive the formula without using any sequences, just uses some elementary graph theory.
The case n=0 and n=1 are special cases, but it turns out that for n=1 the formula is correct.
For the cases n>1,
Let v be the number of intersection points, we know there are n(n-1) of them since there are n(n-1)/2 pairs of circles and each pair has exactly 2 intersection points. These are the vertices of our graph. Now v=n(n-1).
We can now think of the arcs of the circles bounding the regions as edges between the vertices. It is easy to see that the degree of each vertex is 4 (since exactly 2 circles intersect at each intersection point), so by the handshaking lemma, the total number of edges, e = 4v/2 = 2v = 2n(n-1).
We are asked to compute the number of regions f, so by Euler's formula,
f = e - v + 2 = n (n - 1) + 2.
can anybuddy tell me what should be the output for inout 0 & 1.....I am getting WA.
I used BigInt library
Also used the standard formula for the problem!
can anybuddy tell me what should be the output for inout 0 & 1.....I am getting WA.
I used BigInt library
Also used the standard formula for the problem!