結果
問題 | No.2637 Factorize? |
ユーザー | Lisp_Coder |
提出日時 | 2024-05-16 02:30:23 |
言語 | Common Lisp (sbcl 2.3.8) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 1,027 bytes |
コンパイル時間 | 74 ms |
コンパイル使用メモリ | 33,596 KB |
実行使用メモリ | 38,996 KB |
最終ジャッジ日時 | 2024-12-20 10:40:39 |
合計ジャッジ時間 | 2,023 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
27,852 KB |
testcase_01 | AC | 10 ms
26,280 KB |
testcase_02 | AC | 11 ms
29,860 KB |
testcase_03 | AC | 10 ms
25,768 KB |
testcase_04 | AC | 10 ms
27,972 KB |
testcase_05 | AC | 10 ms
25,900 KB |
testcase_06 | AC | 9 ms
25,768 KB |
testcase_07 | AC | 23 ms
38,872 KB |
testcase_08 | AC | 24 ms
36,840 KB |
testcase_09 | AC | 22 ms
36,964 KB |
testcase_10 | AC | 22 ms
36,968 KB |
testcase_11 | AC | 23 ms
36,964 KB |
testcase_12 | AC | 16 ms
30,648 KB |
testcase_13 | AC | 23 ms
36,840 KB |
testcase_14 | AC | 15 ms
32,688 KB |
testcase_15 | AC | 24 ms
38,996 KB |
testcase_16 | AC | 19 ms
36,768 KB |
testcase_17 | AC | 22 ms
38,948 KB |
testcase_18 | AC | 18 ms
38,948 KB |
testcase_19 | AC | 21 ms
36,952 KB |
testcase_20 | AC | 21 ms
34,920 KB |
testcase_21 | AC | 21 ms
34,740 KB |
testcase_22 | AC | 10 ms
29,864 KB |
testcase_23 | AC | 10 ms
26,028 KB |
testcase_24 | AC | 9 ms
29,988 KB |
testcase_25 | AC | 9 ms
27,984 KB |
testcase_26 | AC | 10 ms
27,980 KB |
testcase_27 | AC | 10 ms
27,812 KB |
testcase_28 | AC | 9 ms
25,896 KB |
testcase_29 | AC | 9 ms
25,636 KB |
testcase_30 | AC | 10 ms
29,992 KB |
testcase_31 | AC | 10 ms
29,864 KB |
コンパイルメッセージ
; compiling file "/home/judge/data/code/Main.lisp" (written 20 DEC 2024 10:40:36 AM): ; wrote /home/judge/data/code/Main.fasl ; compilation finished in 0:00:00.016
ソースコード
(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)