Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f9bac45 commit eaf4f91Copy full SHA for eaf4f91
1 file changed
Maths/PrimeCheck.js
@@ -0,0 +1,29 @@
1
+/*
2
+ Modified from:
3
+ https://github.com/TheAlgorithms/Python/blob/master/maths/prime_check.py
4
+
5
+ Complexity:
6
+ O(sqrt(n))
7
+*/
8
9
+const PrimeCheck = (n) => {
10
+ // input: n: int
11
+ // output: boolean
12
+ for (let i = 2; i * i <= n; i++) {
13
+ if (n % i === 0) {
14
+ return false
15
+ }
16
17
+ return true
18
+}
19
20
+const main = () => {
21
+ // PrimeCheck(1000003)
22
+ // > true
23
+ console.log(PrimeCheck(1000003))
24
+ // PrimeCheck(1000001)
25
+ // > false
26
+ console.log(PrimeCheck(1000001))
27
28
29
+main()
0 commit comments