1.23

secje posted @ 2010年5月12日 05:24 in sicp , 830 阅读

这题没什么难度,just modify a little bit from the previos procedure (prime? n)

 

(define (runtime) (current-milliseconds))
(define (square x) (* x x))
(define (next-divisor n)
  (if (= n 2)
      3
      (+ n 2)))
(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 (next-divisor test-divisor)))))
(define (divides? a b)
  (= (remainder b a) 0))
(define (prime? n)
  (= n (smallest-divisor n)))
(define (timed-prime-test n)
  (start-prime-test n (runtime)))
(define (start-prime-test n start-time)
  (if (prime? n)
      (- (runtime) start-time)))
(timed-prime-test 10000000019)
(timed-prime-test 10000000033)
(timed-prime-test 10000000061)

然后输出

594
523
600

previous version

 

(define (runtime) (current-milliseconds))
(define (square x) (* x x))
(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 (divides? a b)
  (= (remainder b a) 0))
(define (prime? n)
  (= n (smallest-divisor n)))
(define (timed-prime-test n)
  (start-prime-test n (runtime)))
(define (start-prime-test n start-time)
  (if (prime? n)
      (- (runtime) start-time)))
(timed-prime-test 10000000019)
(timed-prime-test 10000000033)
(timed-prime-test 10000000061)

输出

1507
1029
1203

两倍的关系还是比较相近的

NCERT 8th Class Solu 说:
2022年9月08日 08:53

Those Secondary Education Class VIII Standard students can download subject wise solutions in chapter wide for all subjects of the course introduced by the school education department for Hindi medium, English medium, NCERT 8th Class Solutions Urdu medium students designed and suggested by the National Council of Educational Research and Training (NCERT).The NCERT has introduced those Secondary education STD-8 subject wide answer solutions for Term-1, Term-2, Term-3, Term-4 in session wide for Session-1 & Session-2 (Part-A and Part-B) exams and published at their official web portals of NCERT & ePathshala, and various private websites also shared to the class 8th standard students studying at all regions of the country.

netflix.com/tv8 说:
2023年7月22日 04:44

Netflix bietet eine Reihe von Filmen, Fernsehsendungen und Originalinhalten für ein angemessenes monatliches Abonnement. Netflix kann auf Smart TV, Streaming-Geräten oder modernen Spielsystemen mit Internetverbindung angezeigt werden. netflix.com/tv8 Bei einigen Geräten müssen Sie das Gerät aktivieren, bevor Sie sich anmelden. Dies ist üblich bei neuen Geräten oder solchen, die gerade Softwareänderungen erhalten haben.

Gujarat 1st Class T 说:
2023年8月22日 00:31

Gujarat Board Primary School Academic Year Close in Every Year Month of April, Gujarat Board Elementary School new Academic Year Open in Every Year Month of Jun, Every Year Gujarat State Wise Class More Than 50 Laks of Students Attended, Every Year Primary School Education Department Government of Gujarat Distribution in Textbook in Gujarati / English / Hindi Medium.The Printed Gujarat Class Gujarat 1st Class Textbook 2024 Textbook 2024 are Distributed Through Cooperative Institutions All over Gujarat. Vendors are Linked to the Distribution of Textbooks with Distributors in each District. Gujarat Board Class Book 2024 are easily Accessible to All Students of This System, This will assist in improving the Quality of Teaching by Understanding the Type of Difficulties Faced by Students.

pavzi.com 说:
2024年1月20日 05:28

Pavzi website is a multiple Niche or category website which will ensure to provide information and resources on each and every topic. Some of the evergreen topics you will see on our website are Career, Job Recruitment, Educational, Technology, Reviews and others. pavzi.com We are targeting mostly so it is true that Tech, Finance, and Product Reviews. The only reason we have started this website is to make this site the need for your daily search use.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter