-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
53 additions
and
14 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### 最小公倍数 | ||
|
||
#### 定义 | ||
|
||
若有一个数 `X`, 可以被另外两个数 `A` 、 `B` 整除, 且 `X` 大于(或等于) `A` 和 `B`, 则 `X` 为 `A` 和 `B` 的公倍数。 `A` 和 `B` 的公倍数有无限个, 而所有的公倍数中, 最小的公倍数就叫做最小公倍数。 | ||
|
||
**Note** | ||
|
||
$$ lcm(a, b) = \frac{gcm(a, b)}{|a * b|} $$ | ||
|
||
### 参考资料 | ||
|
||
[最小公倍数 - wiki](https://zh.wikipedia.org/zh-cn/%E6%9C%80%E5%B0%8F%E5%85%AC%E5%80%8D%E6%95%B8) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2020-01-30 11:42:57 | ||
* @LastEditors : Rainy | ||
* @LastEditTime : 2020-01-31 13:23:08 | ||
*/ | ||
|
||
import { lcm } from '.'; | ||
|
||
test('lcm(5, 10) should be 10', () => { | ||
expect(lcm(5, 10)).toEqual(10); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* @Author: Rainy | ||
* @Date: 2020-01-31 12:33:43 | ||
* @LastEditors : Rainy | ||
* @LastEditTime : 2020-01-31 13:25:56 | ||
*/ | ||
|
||
import { gcd_optimal } from '../gcd'; | ||
|
||
// the least common multiple | ||
export function lcm(a: number, b: number): number { | ||
return ((a === 0) || (b === 0)) ? 0 : Math.abs(a * b) / gcd_optimal(a, b); | ||
} |