Last active
January 21, 2021 02:00
-
-
Save yanfeng42/c95979d09f1728a35710214be1ad342d to your computer and use it in GitHub Desktop.
sicp 1.2.6, 关于费马小定理实现中的, 若a^n % b = x, 则: a^2n % b = x^2 % b 的简易证明
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;费马小定理: 如果 n 是一个素数, a是小于n 的任意正整数, 那么 a的n次方 与 a 模n同余(除以 n 的余数相同). | |
; 计算一个数的幂, 对另一个数取模的结果. | |
(define (fermat-test n) | |
(define (try-it a) | |
; 因为 a 小于n, 所以 a/n 的余数就是 a. | |
(= (expmode a n n) a) | |
) | |
(try-it (+ 1 (random (- n 1)))) | |
) |
Author
yanfeng42
commented
Jan 21, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment