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 | 29 | 30 |
Tags
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ์นด์นด์ค ์ฝํ
- app router emotion
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ nodejs
- ์ค์ฝํ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- suspense ๋น๋๊ธฐ
- js ์ค์ฝํ
- ๋ฐฑ์ค 1339๋ฒ js
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- suspense ๋์์๋ฆฌ
- emotion RSC
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- next13 emotion
- suspense react-query
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- suspense ๋ณ๋ชฉํ์
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- js
- ๋ฐฑ์ค 2108 nodejs
- emtion app router
- ์ต์ ๋์ฒด์ด๋
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- ๊ตฌ๋ฆํค
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ๋ฌธ์์ด ์์ถ
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 9020๋ฒ] ๊ณจ๋๋ฐํ์ ์ถ์ธก - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 9020๋ฒ] ๊ณจ๋๋ฐํ์ ์ถ์ธก - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 1. 18. 18:43728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/9020
const fs = require('fs');
let input = fs
.readFileSync('dev/stdin')
.toString()
.trim()
.split('\n')
.map((v) => +v);
input.shift();
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;
};
const primeArr = [];
for (let i = 2; i <= 10000; i++) {
if (isPrime(i)) {
primeArr.push(i);
}
}
input.filter((v) => {
if (primeArr.includes(v / 2)) {
console.log(`${v / 2} ${v / 2}`);
} else {
const arr = [];
for (let i = 0; i < primeArr.length; i++) {
for (let j = i + 1; j < primeArr.length; j++) {
if (primeArr[i] + primeArr[j] === v) {
arr.push([primeArr[i], primeArr[j]]);
break;
}
if (primeArr[i] > v) {
break;
}
}
}
arr.sort((a, b) => {
const aValue = a[1] - a[0];
const bValue = b[1] - b[0];
return aValue - bValue;
});
console.log(`${arr[0][0]} ${arr[0][1]}`);
}
});
์์ ํ๋ณ ํจ์๋ฅผ ๋ง๋ค๊ณ 10000์ดํ์ ์์๋ฅผ primeArr์ pushํ๋ค.
๊ทธ ํ 10000์ดํ์ ์ง์ ์ ๋ ฅ๊ฐ์ ๋ํด ์์์ ํฉ์ผ๋ก ์ ์๋๋ ๊ฐ๋ค์ arr ๋ฐฐ์ด์ ๋ฃ๊ณ ex) 16 => [3,13], [5,11]
sortํจ์๋ฅผ ์ด์ฉํด ๊ฐ์ ์ฐจ์ด๊ฐ ๊ฐ์ฅ ์์ ๊ฒ๋ค๋ก ์ ๋ ฌํ ํ 0๋ฒ์งธ ์ธ๋ฑ์ค๋ฅผ ์ถ๋ ฅํ๋ฉด ๋๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments