Ladies_Man

НОД, НОК и проверка числа на простоту

Dec 17th, 2013
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.37 KB | None | 0 0
  1. (define (my-gcd a b)
  2.      (if (= a b)
  3.           a
  4.          (if (< a b)
  5.              (my-gcd a (- b a))
  6.              (my-gcd (- a b) b))))
  7.  
  8.  
  9. (define (my-lcm a b)
  10.   (/ (* a b) (my-gcd a b)))
  11.  
  12. (define (prime? n)
  13.   (not (or (= n 1)
  14.            (= (remainder n 2) 0)
  15.            (= (remainder n (do ((i 2 (+ i 1)))
  16.                                ((> i (/ n 2)) i))) 0))))
Advertisement
Add Comment
Please, Sign In to add comment