Racket Programming. Where am I going wrong?

前端 未结 2 701
广开言路
广开言路 2020-12-12 05:31

The question i\'m trying to answer:
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

Where am I goin

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 05:57

    Easy answer:

    $ factor 600851475143
    600851475143: 71 839 1471 6857
    

    More serious answer: Your prime? function is indeed broken; I'm not even certain what it's trying to do. (Also, your (= n 2) test is too late to be useful: the (even? n) test has trumped it.)

    My suggestion: Implement the Sieve of Eratosthenes. Here's my implementation.

提交回复
热议问题