SICP 全笔记

Exercise 1.24. Modify the timed-prime-test procedure of exercise 1.22 to use fast-prime? (the Fermat method), and test each of the 12 primes you found in that exercise. Since the Fermat test has (log n) growth, how would you expect the time to test primes near 1,000,000 to compare with the time needed to test primes near 1000? Do your data bear this out? Can you explain any discrepancy you find?

对每个数字进行 sqrt(n) 次检测,在 1000000 附近和 1000 附近的时间是 1901 ,与 log(n) 的增加值差别比较大。因为 Fermat 方法只是在计算 $a^n$ ,当 n 非常大的时候需要耗费更多的时间,在相同步数的情况下,计算更耗时间的大数与小数之间的步数增长即使为 log(n) 在这里也很难观察得到。