Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 359690c

Browse files
Add 소수-찾기.js
1 parent b948b28 commit 359690c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎level-1/소수-찾기.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,25 @@ function solution(n) {
3131
if (isPrime(i)) answer++;
3232
}
3333
return answer;
34+
}
35+
36+
//정답 3 - prove-ability
37+
// 소수 판별 로직
38+
function isPrime(n) {
39+
// n 제곱근 후 올림
40+
for (let i = 2, len = Math.ceil(Math.sqrt(n)); i <= len; i++) {
41+
if (n % i === 0) return false;
42+
}
43+
return true;
44+
}
45+
46+
function solution(n) {
47+
let count = 0;
48+
// 1부터 n까지 반복적으로 접근 - i
49+
for(let i = 1; i <= n; i++) {
50+
// i 가 소수인지 확인 후 count++
51+
if(isPrime(i)) count++;
52+
}
53+
54+
return count;
3455
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /