This commit is contained in:
ikselven 2017-08-08 23:15:05 +02:00
commit ed772e7550

View file

@ -1,10 +1,12 @@
#lang racket #lang typed/racket
(require math/number-theory) (require math/number-theory)
(: max-prime-factor (-> Integer (U False Integer)))
(define (max-prime-factor x) (define (max-prime-factor x)
(if (prime? x) x (if (prime? x) x
(for/or ((i (filter prime? (range 2 (sqrt x))))) (for/or ((i (filter prime? (range 2 (ceiling (assert (sqrt x) real?)))))
(if (zero? (remainder x i)) (max-prime-factor (quotient x i)) #f)))) #:when (zero? (remainder x i)))
(max-prime-factor (quotient x i)))))
(max-prime-factor 600851475143) (max-prime-factor 600851475143)