0%

复习大学算法课

挺多东西时间长了不接触都忘记了

10÷6=1...4
10是被除数,6是除数,1是商,4是余数

4 == 10 % 6

两数相除,除数变被除数,余数变除数

设余数为x

1
2
3
4
5
         n
----> x
m % n =
-> n
<-----------x
1
2
3
4
5
6
7
8
9
10
11
12
!function() {
const log = console.log
function gcd(m,n) {
while(n > 0){
let x = n
n = m % n
m = x
}
return m
}
log(gcd(12,16))
}()