ifK<=2 # if K<=2: $1=K*K # $0 := (K**2+1)*(K**3+3*K) = U_6(K,-1); $0=$1+1 # $1 := (K**3+3*K)**2+2 = V_6(K,-1); $1=$1+3 $1=$1*K $0=$0*$1 $1=$1*$1 $1=$1+2 end # end ifK>=3 # if K>=3: $0=K # $0 := K = U_2(K,-1); $1=K*K # $1 := K**2+2 = V_2(K,-1); $1=$1+2 end # end $3=100000/K while$0<$3 # while $0<10**5/K: $0=$0*$1 # $0,$1 := ($0*$1),($1*$1-2) = U_{2n}(K,-1),V_{2n}(K,-1); (where n mod 2 = 0) $1=$1*$1 $1=$1-2 end # end $3=K*$0 # $1,$0,$2 := ($1+(K*$0))/2,$0,($1-(K*$0))/2 = U_{n+1}(K,-1),U_{n}(K,-1),U_{n-1}(K,-1); (where n mod 2 = 0) $2=$1-$3 $2=$2/2 $1=$1+$3 $1=$1/2 $4=N/K while$1<=$4 # while $1 <= (N/K): $2=$1 # $1,$0,$2 := (($1*K+$0)*K+$1),($1*K+$0),($1); $3=$1*K $0=$3+$0 $1=$0*K $1=$1+$2 end # end if$0<=$4 # if $0 <= (N/K): $2=$0 # $1,$0,$2 := ($1*K+$0),($1),($0); $0=$1 $1=$0*K $1=$1+$2 end # end if$0<=N # if $0 <= N: $3=N/$0 # $3 := N/$0+1; $3=$3+1 $1=$1*$3 # $1 := $1*$3+$0; $1=$1+$0 $0=$0*$3 # $0 := $0*$3+$2; $0=$0+$2 end # end $2=$1-$0 # $0,$2 := ($0*N),($1-$0); $0=$0*N ifM==0 # if M==0: $2=$2+K # $0 := $0-($2+K-1)/K; $2=$2-1 $2=$2/K $0=$0-$2 end # end ifM>1 # if M>1: $3=M-1 # $3 := M-1; $4=$2/K # $0 := $0+($2/K)*(M-1); $4=$4*$3 $0=$0+$4 $2=$2%K # $0 := $0+($2%K)*(M-1)/K; $2=$2*$3 $2=$2/K $0=$0+$2 end # end $0=$0/$1 # return ($0/$1+N); $0=$0+N return$0