HP Forums

Full Version: (50g) Sum of Divisors to an Integer Power
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For stack input

Z an Integer
P an integer Real

the programme returns the sum of

Divisor^P

NB For P=0. the programme returns the number of divisors.

Size: 202.5

CkSum: # 2199h

Code:
::
  CK2&Dispatch
  # FF1
  ::
    %ABSCOERCE
    ::
      DUP#0=csedrp
      {
        ROTDROPSWAP
        %1+
        FPTR2 ^R>Z
        FPTR2 ^RMULText
      }
      {
        3PICK
        ROT
        COERCE
        #1+
      }
      OVER
      >TCOMP
      {
        #*
        FPTR2 ^PPow#
        ZINT 1
        FPTR2 ^QSub
        ROT
      }
      &COMP
      SWAP
      >TCOMP
      {
        FPTR2 ^PPow#
        ZINT 1
        FPTR2 ^QSub
        FPTR2 ^ZQUOText
        FPTR2 ^QMul
      }
      &COMP
    ;
    1LAMBIND
    ::
      FPTR2 ^ZAbs
      FPTR2 ^DupQIsZero?
      caseSIZEERR
      FPTR2 ^DupZIsOne?
      ?SEMI
      FPTR2 ^MZSQFF
      #2/
      ZINT 1
      SWAP
      ZERO_DO
      1GETLAM
      COMPEVAL
      LOOP
    ;
    ABND
  ;
;
Reference URL's