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 8fc463b commit f538625Copy full SHA for f538625
素数.js
@@ -0,0 +1,26 @@
1
+//素数:因子除了1和它本身的数
2
+
3
+//判断是否是素数
4
+function isPrimeNumber(num) {
5
+ let sqrt = Math.ceil(Math.sqrt(+num))
6
7
+ for(let i = 2; i <= sqrt; i++){
8
+ if(num % i == 0) {
9
+ return false
10
+ }
11
12
+ return true
13
+}
14
15
16
+//获取某一范围内所有的素数
17
+function getPrimeNumer(num) {
18
+ let arr = []
19
+ for(let i = 1; i <= num; i++){
20
+ if(isPrimeNumber(i)){
21
+ arr.push(i)
22
23
24
25
+ return arr
26
0 commit comments