(require 'calc-ext)
(defvar calc-command-flags nil)
(defun find-factor (num)
(catch 'found
(let ((i 2))
(while (math-lessp (math-sub i 1) (math-floor (math-sqrt num)))
(if (math-equal (math-mod num i) 0)
(throw 'found i)
(setq i (math-add i 1))) ))))
(defun math-sum (lst)
(let ((rst 0))
(dolist (elt lst rst)
(setq rst (math-add rst elt)) )))
(let ((i 2)
(n (string-to-number (car argv)))
prime-lst)
(while (<= i n)
(if (not (find-factor i))
(push i prime-lst) )
(setq i (1+ i)))
(princ (math-format-value (math-sum prime-lst)))
(princ "\n"))
メモ
- calc の多倍長整数 bignum を文字列に変えるには math-format-value を使えばよい.