HP Forums

Full Version: (38G) Integer Partitions (Using Ramanujam's Method)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For input N a positive integer the programme returns the number of integer partitions in Ans & displays the result.

Faster than Gauss' method but subject to inaccuracies for higher values of N.

Improvements welcome.

INT(Ans)►N:
IF N<1
THEN
0:
ELSE
0►B:
√(2/3)►H:
1►C:
N-1/24►F:
√F►R:
R*H*π►G:
π*H/F►H:
F*R►F:
2*π►P:
2*N►Q:
DO
0►E:
FOR D=1 TO C STEP 1;
C►I:
D►J:
DO
I MOD J►K:
J►I:
K►J:
UNTIL
K==0
END:
IF I==1
THEN
COS(π*( Σ(I=1,C-1,(FRAC((D*I)/C)-.5)*(I/C-.5))+.25-(Q*D)/C))+E►E:
END:
END:
G/C:
(COSH(Ans)*H/C-SINH(Ans)/F)*√C/P►O:
C+1►C:
O*E+B►B:
UNTIL
ROUND(O+B,0)==ROUND(B,0)
END:
ROUND(B,0)►B:
END:
ERASE:
DISP 2;" p("N")":
DISP 4;" "B:
FREEZE:
Reference URL's