diff --git a/src/__tests__/primes.spec.ts b/src/__tests__/primes.spec.ts index e5d0390..771196e 100644 --- a/src/__tests__/primes.spec.ts +++ b/src/__tests__/primes.spec.ts @@ -47,6 +47,12 @@ describe('Primeness detector', () => { expect(isPrime(n)).toBe(false); } }); + it('works for 62837327', () => { + expect(isPrime(62837327)).toBe(false); + }); + it('works for 62837303', () => { + expect(isPrime(62837303)).toBe(true); + }); }); describe('Lists of primes', () => { diff --git a/src/primes.ts b/src/primes.ts index 481be00..48d776b 100644 --- a/src/primes.ts +++ b/src/primes.ts @@ -118,6 +118,9 @@ export function isPrime(n: number) { throw new Error('Prime check only implemented up to 62837328'); } for (const prime of PRIMES) { + if (prime * prime > n) { + return true; + } if (n % prime === 0) { return false; }