Add primality tests.

This commit is contained in:
Oleksii Trekhleb 2018-04-16 22:09:41 +03:00
parent 81ca672f5a
commit f724bd5353
2 changed files with 3 additions and 1 deletions

View File

@ -16,6 +16,8 @@ export default function primalityTest(testFunction) {
expect(testFunction(4)).toBeFalsy();
expect(testFunction(6)).toBeFalsy();
expect(testFunction(12)).toBeFalsy();
expect(testFunction(14)).toBeFalsy();
expect(testFunction(25)).toBeFalsy();
expect(testFunction(192)).toBeFalsy();
expect(testFunction(200)).toBeFalsy();
expect(testFunction(400)).toBeFalsy();

View File

@ -18,7 +18,7 @@ export default function trialDivision(number) {
// If there is no dividers up to square root of n then there is no higher dividers as well.
const dividerLimit = Math.sqrt(number);
for (let divider = 3; divider < dividerLimit; divider += 2) {
for (let divider = 3; divider <= dividerLimit; divider += 2) {
if (number % divider === 0) {
return false;
}