$0=N+1 # $0,$1 := (N+1),(N/K); $1=N/K $2=N*N # $2,$3 := (N*N),(K*N); $3=K*N while$0>$1 # while $0>$1: $0=$1 # $0,$1 := $1,(($1*$1+N*N)/(2*$1+K*N)); $4=$1*$1 $1=2*$1 $4=$4+$2 $1=$1+$3 $1=$4/$1 end # end ifM>1 # if M>1: $0=$0+1 # $0 := $0+1; end # end $2=K*$0 # $2 := K*$0+1-M; $2=$2+1 $2=$2-M $3=$3+1 # $3 := K*N+1-M; $3=$3-M while$2>0 # while $2>0: $1=$3 # $1,$2,$3,$5 := ($3/$2),($3%$2),($2),(1-$5); $3=$2 $2=$1%$3 $1=$1/$3 $5=1-$5 if$1!=K # if $1!=K: $2=0 # $2 := 0; if$1>K # if $1>K: $5=1-$5 # $5 := 1-$5; end # end end # end end # end $0=$0-$5 # return ($0-$5+N); $0=$0+N return$0