The closed form expression 1+6*2n-1 seems close,
...
The given closed form shows an understandable accounting of the required executions, as N increases from zero.
The execution count includes:
1. One, for the initial execution, which directly returns 1, if N is zero
2. Additional executions, in Sets of six, comprising executions of the entire formula, when N is not zero.
3. The doubling of the number of Sets, as N increments, owing to recalculation of previous results.
4. The total, which is simply 1 plus 6 times the partial sum of the powers of 2.
Are you asking for a different closed form; one that gathers multiply-calculated results into 137 groups, then sums those numbers? Perhaps making those tables for a few smaller values of N will suggest the form of that expression.
Programming question: could execution time be drastically reduced, by storing previously calculated values of P and calling them from a table if needed again?
As for programming:
Of course, the execution time could be reduced by storing calculated results in an array and taking them from there when available. Recursive code seems most economical and simple, but it is dangerous. For this problem, I would use non-recursive code.
Modifying Bushindo's code to store results in array and do itterations instead of recursion we bring execution down to just 137 itterations:
Define Array P[143];
P[-5]=P[-4]=P[-3]=P[-2]=P[-1]=0;
P[0]=1;
FOR N=1 TO 137
P[N]=(P[N-1]+P[N-2]+P[N-3]+P[N-4]+P[N-5]+P[N-6])/6
PRINT P[N];
(Dont' ask me what language it is in.)
Execution time notwithstanding, recursive code gives rise to interesting math questions and Fibonacci like series.
Edited by Prime, 20 January 2013 - 04:36 AM.