結果

問題 No.2637 Factorize?
ユーザー Lisp_CoderLisp_Coder
提出日時 2024-05-16 02:30:23
言語 Common Lisp
(sbcl 2.3.8)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 36,780 KB
実行使用メモリ 41,036 KB
最終ジャッジ日時 2024-05-16 02:30:27
合計ジャッジ時間 3,146 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
25,772 KB
testcase_01 AC 11 ms
28,108 KB
testcase_02 AC 10 ms
25,640 KB
testcase_03 AC 11 ms
27,856 KB
testcase_04 AC 10 ms
25,896 KB
testcase_05 AC 11 ms
25,772 KB
testcase_06 AC 11 ms
29,856 KB
testcase_07 AC 24 ms
36,964 KB
testcase_08 AC 23 ms
36,964 KB
testcase_09 AC 24 ms
36,712 KB
testcase_10 AC 29 ms
41,036 KB
testcase_11 AC 26 ms
40,908 KB
testcase_12 AC 17 ms
30,648 KB
testcase_13 AC 25 ms
40,888 KB
testcase_14 AC 15 ms
30,640 KB
testcase_15 AC 25 ms
36,832 KB
testcase_16 AC 22 ms
32,824 KB
testcase_17 AC 24 ms
36,904 KB
testcase_18 AC 19 ms
32,744 KB
testcase_19 AC 24 ms
34,792 KB
testcase_20 AC 22 ms
38,964 KB
testcase_21 AC 23 ms
38,668 KB
testcase_22 AC 11 ms
26,024 KB
testcase_23 AC 11 ms
27,724 KB
testcase_24 AC 10 ms
25,900 KB
testcase_25 AC 11 ms
26,024 KB
testcase_26 AC 12 ms
25,768 KB
testcase_27 AC 13 ms
25,896 KB
testcase_28 AC 13 ms
25,896 KB
testcase_29 AC 11 ms
25,768 KB
testcase_30 AC 11 ms
25,900 KB
testcase_31 AC 11 ms
25,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 16 MAY 2024 02:30:24 AM):

; wrote /home/judge/data/code/Main.fasl
; compilation finished in 0:00:00.104

ソースコード

diff #

(defun sieve (limit)
  (let ((is-prime (make-array (1+ limit) :initial-element t)))
    (setf (aref is-prime 0) nil
          (aref is-prime 1) nil)
    (loop for i from 2 to (isqrt limit) do
         (when (aref is-prime i)
           (loop for j from (* i i) to limit by i do
                (setf (aref is-prime j) nil))))
    (loop for i from 2 to limit
          when (aref is-prime i)
          collect i)))

(defun prime-factors (n primes)
  (let ((factors '()))
    (dolist (prime primes)
      (loop while (zerop (mod n prime)) do
           (push prime factors)
           (setf n (/ n prime))))
    (if (> n 1) (push n factors))
    (nreverse factors)))

(defun first-factor-pair (n)
  (if (<= n 1)
      (list 1 1)
      (let* ((limit (isqrt n))
             (primes (sieve limit))
             (factors (prime-factors n primes)))
        (list 1 (apply #'* factors)))))

(defun main ()
  (let ((n (parse-integer (read-line))))
    (let ((pair (first-factor-pair n)))
      (format t "~{~a~^ ~}~%" pair))))

(main)
0