Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (square x) (* x x))
- (define (divides? a b)
- (= (remainder b a) 0))
- (define (smallest-divisor n)
- (find-divisor n 2))
- (define (find-divisor n test-divisor)
- (cond ((> (square test-divisor) n) n)
- ((divides? test-divisor n) test-divisor)
- (else (find-divisor n (+ test-divisor 1)))))
- (define (prime? n)
- (= n (smallest-divisor n)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement