Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- emotion RSC
- js ์ค์ฝํ
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- app router emotion
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ๋ฐฑ์ค 1339๋ฒ js
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค
- suspense ๋น๋๊ธฐ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- js
- suspense ๋์์๋ฆฌ
- suspense react-query
- emtion app router
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ์ต์ ๋์ฒด์ด๋
- next13 emotion
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- suspense ๋ณ๋ชฉํ์
- ๋ฐฑ์ค 2108 nodejs
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ์นด์นด์ค ์ฝํ
- ์ค์ฝํ
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 4948๋ฒ] ๋ฒ ๋ฅดํธ๋ ๊ณต์ค - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 4948๋ฒ] ๋ฒ ๋ฅดํธ๋ ๊ณต์ค - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 1. 17. 20:26728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/4948
4948๋ฒ: ๋ฒ ๋ฅดํธ๋ ๊ณต์ค
๋ฒ ๋ฅดํธ๋ ๊ณต์ค์ ์์์ ์์ฐ์ n์ ๋ํ์ฌ, n๋ณด๋ค ํฌ๊ณ , 2n๋ณด๋ค ์๊ฑฐ๋ ๊ฐ์ ์์๋ ์ ์ด๋ ํ๋ ์กด์ฌํ๋ค๋ ๋ด์ฉ์ ๋ด๊ณ ์๋ค. ์ด ๋ช ์ ๋ ์กฐ์ ํ ๋ฒ ๋ฅดํธ๋์ด 1845๋ ์ ์ถ์ธกํ๊ณ , ํํ๋ํฐ ์ฒด๋น์ผ
www.acmicpc.net
const fs = require('fs');
let input = fs
.readFileSync('dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => +v);
input.pop();
const isPrime = (num) => {
if (num === 1) return false;
for (let i = 2; i <= Math.sqrt(num); i += 1) {
if (num % i === 0) {
return false;
}
}
return true;
};
input.filter((v) => {
let count = 0;
for (let i = v + 1; i <= v * 2; i++) {
if (isPrime(i)) {
count++;
}
}
console.log(count);
});
isPrime ํจ์์์ ์ ๊ณฑ๊ทผ์ ์ด์ฉํด ํจ์จ์ ์ผ๋ก ๊ตฌํํ ์ ์๋ค.
๊ธฐ๋ณธ์ ์ธ for(let i = 2; i < num; i++)์ ์์ํ๋ณ์ ์ฌ์ฉํ๊ฒ๋๋ฉด ์๊ฐ์ด๊ณผ ์ค๋ฅ๊ฐ ๋๋ ๊ฒฝ์ฐ๊ฐ ์๋นํ ๋ง์๊ฒ์ด๋ค.
์ ๊ณฑ๊ทผ์ ์ด์ฉํด ํ๋ณํ๋๋ก ํ์!
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments