PIB - Pibonacci

You might have heard of the Fibonacci numbers and of the number pi. If you let these two ideas merge, a new and esoteric concept comes into being: the Pibonacci numbers. These can be defined for real x>=0 by:

P(x) = 1 for 0<=x<4
P(x) = P(x-1) + P(x-pi) for 4<=x,

where pi = 3.1415926535... In this problem, you are asked to compute P(x) for a given x.

Input file specification

The input file contains several non-negative integer numbers (less than 30000) each on a separate line. The last line contains -1 marking the end of the input file.

Output file specification

For each non-negative real number in the input file, output the corresponding Pibonacci number. If the Pibonacci number be more than 50 digits long, divide it on the consecutive lines, outputting 50 digits on each (the last line may contain less digits).

Example

Input file:
0
4
11
-1
Output file:
1
2
20

Added by:Fudan University Problem Setters
Date:2007-12-01
Time limit:7s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:IPSC 2001; standard program and test data by Blue Mary

hide comments
2015-07-01 14:18:27
Could I have the results for n=29 to n =50?
2013-06-14 19:39:13 wisfaq
great problem, enjoyed it very much
2012-10-25 11:22:02 :D
It should not work. I did the same the first time around. If you analyze it, you'll see you will generate way to many intermediate values. You need to analyze call tree and deduce some formula from there. Definitively not an easy problem!
2012-06-05 13:40:43 Out0fbounds
recursion with memorization not working... plz help
2011-05-27 02:34:16 [Rampage] Blue.Mary
(1) Each integer in the input file is less than 30000. Number of test cases is small.
(2) The original IPSC problem states that.
2011-05-26 23:29:09 Erick Wong
Clarifications:

Is 30000 a bound on the number of inputs, or the size of each input?

If the input consists of non-negative integers, why refer to real numbers in the output section?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.