操作
  Problem 3 » 履歴 » リビジョン 3
      « 前 |
    リビジョン 3/4
      (差分)
      | 次 »
    
    Noppi, 2023/12/27 12:14 
    
    
Problem 3¶
Largest Prime Factor¶
The prime factors of $13195$ are $5, 7, 13$ and $29$.
What is the largest prime factor of the number $600851475143$?
最大の素因数¶
13195 の素因数は 5, 7, 13, 29 である.
600851475143 の素因数のうち最大のものを求めよ.
#!r6rs
#!chezscheme
(import (chezscheme))
(define answer-3
  (let* ([n 600851475143]
         [check-max (isqrt n)])
    (let loop ([current 3] [rest n] [max-prime 1])
      (cond
        [(< check-max current) max-prime]
        [(zero? (mod rest current))
         (loop current (div rest current) current)]
        [else (loop (+ current 2) rest max-prime)]))))
(printf "3: ~D~%" answer-3)
Noppi が2023/12/27に更新 · 3件の履歴