BOMARBLE - D - Playing with Marbles

PROBLEM D

 PLAYING WITH MARBLES

Pablo was assigned in his class to construct pentagons inside pentagons with marbles but he doesn’t know how many marbles he will need. He knows that for one pentagon he needs 5 marbles

Imagen2

The only way he knows to insert a second pentagon is putting a marble in the middle of each segment and drawing three lines as shown. He puts a marble in the intersecting lines and removes them. To insert a third pentagon inside he first divides all segments in two including the ones that are not needed, and repeats the procedure. Drawing a second pentagon will require 12 marbles. A third pentagon will require 22 marbles. Given the information of how many pentagons will be created, write a program to calculate the number of marbles needed.

Input

The input contains several test cases. Each test case contains one integer N indicating the number of pentagons to create (1<=N<=103). The end of input is indicated by a line containing only one zero.

Output

For each test case in the input, your program must print a single line, containing one single integer, the number of marbles required. 

Sample Input
1
2
3
0

Sample Output
5
12
22

Added by:Alvaro Javier Medina Balboa
Date:2010-05-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C C++ 4.3.2 CPP JAVA

hide comments
2015-04-07 07:21:08 GAURAV CHANDEL
simple formula to get AC
2015-03-26 14:45:35 [Mayank Pratap]
Enjoyed this questions...These questions keep beginners like me motivated :)
2015-01-29 21:08:35 MKM
You know the problem is quite easy when I can even get the series -_-
2014-12-31 01:54:39 Rajat (1307086)
To iterate is human....
To recurse divine...
To tabulate recursion is.....(no words for that)
2014-12-02 09:30:45 Pascual Pérez Abella
You can find the image in this doc:
www.spoj.com/UMSA4/UMSA4/content/SetProblemas.pdf

--ans(Francky)--> Thanks for the link ; I've insert it again in the body.

Last edit: 2014-12-02 10:04:38
2014-06-08 00:26:41 DreamBig
More test cases:

Input:
4
5
6
7
8
9
1000

Output:
35
51
70
92
117
145
1502501
2014-05-21 09:34:59 pvkcse
easiest problem solved in spoj...why not for python and other languages...!!!
2013-08-20 07:03:41 ISHANI
more test cases:-
input:-
4
5
10
100
1000
output:-
35
51
176
15251
1502501
2013-10-24 18:46:12 aqfaridi
simple to derive formula for it.
2012-09-29 00:39:14 nikoo28
oeis comes to rescue...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.