$0=N+1 $1=N/K $2=N*N $3=K*N ifK<=3 ifK==1 $1=N*1134903170 $1=$1/1836311903 end ifK==2 $1=N*1311738121 $1=$1/3166815962 end ifK==3 $1=N*606529080 $1=$1/2003229469 end $0=$1 end while$0>$1 $0=$1 $4=$1*$1 $1=2*$1 $4=$4+$2 $1=$1+$3 $1=$4/$1 end $0=$0+N return$0