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 | 31 |
Tags
- suspense ๋น๋๊ธฐ
- ๋ฐฑ์ค 1339๋ฒ js
- suspense react-query
- ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ด ์์ถ
- ์ค์ฝํ
- ๋ฐฑ์ค 2108 nodejs
- ๋ฆฌ์กํธ์ฟผ๋ฆฌ suspense
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง ํ๊ณ
- ์ต์ ๋์ฒด์ด๋
- emtion app router
- TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more:
- ์๋ฐ์คํฌ๋ฆฝํธ ์ค์ฝํ
- next13 emotion
- ๋ฐฑ์ค 1339๋ฒ ์๋ฐ์คํฌ๋ฆฝํธ
- app router emotion
- ์นด์นด์ค ์ฝํ
- ์ฌ์ฉ์ฑ ๊ฐ์
- js ๋ฌธ์์ด ์์ถ
- ๊ตฌ๋ฆํค ์ฑ๋ฆฐ์ง
- ๋ฐฑ์ค 1339๋ฒ nodejs
- emotion RSC
- ๋ฐฑ์ค 2108 ์๋ฐ์คํฌ๋ฆฝํธ
- ํ๋ก๊ทธ๋๋จธ์ค ๋ฌธ์์ด ์์ถ
- js
- suspense ๋ณ๋ชฉํ์
- js ์ค์ฝํ
- suspense ๋์์๋ฆฌ
- ํ๋ก๊ทธ๋๋จธ์ค ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
- ๊ตฌ๋ฆํค
- js ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
Archives
- Today
- Total
Lennon FE
[๋ฐฑ์ค 1747๋ฒ] ์์&ํฐ๋ฆฐ๋๋กฌ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) ๋ณธ๋ฌธ
๐ฅ Algorithm/Baekjoon
[๋ฐฑ์ค 1747๋ฒ] ์์&ํฐ๋ฆฐ๋๋กฌ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs)
Lennon 2022. 1. 21. 19:12728x90
๋ฐ์ํ
https://www.acmicpc.net/problem/1747
const fs = require('fs');
let input = +fs.readFileSync('dev/stdin').toString().trim();
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 isPalindrome = (num) => {
let stringNum = String(num);
const len = stringNum.length / 2;
let first = '';
let last = '';
if (stringNum.length % 2 === 1) {
for (let i = 0; i < len - 1; i++) {
first += stringNum[i];
}
for (let i = stringNum.length - 1; i > len; i--) {
last += stringNum[i];
}
} else {
for (let i = 0; i < len; i++) {
first += stringNum[i];
}
for (let i = stringNum.length - 1; i > len - 1; i--) {
last += stringNum[i];
}
}
if (first === last) {
return true;
}
return false;
};
for (let i = input; i < Number.MAX_SAFE_INTEGER; i++) {
if (isPrime(i) && isPalindrome(i)) {
console.log(i);
break;
}
}
isPrime => ์์ ํ๋ณ ํจ์
isPalindrome => ํฐ๋ฆฐ๋๋กฌ ํ๋ณ ํจ์
์ ์ํ ์ - 11, 4664, 45554 ๋ฑ ๋ชจ๋ ํฐ๋ฆฐ๋๋กฌ ๊ฒธ ์์์ด๋ค. (2์๋ฆฌ, 4์๋ฆฌ ๋ฑ ํฐ๋ฆฐ๋๋กฌ์ ์กด์ฌํ๋ค)
์ ๋ ฅ๊ฐ์ ์ต๋๊ฐ์ด 1,000,000์ด ์ต๋ ์ถ๋ ฅ์ด 1,000,000์ด๋ผ๋ ์๋ฆฌ๊ฐ ์๋๋ผ 1,000,000๋ถํฐ ์์ํ๋ค๋ ๋ง์ด๋ค.
์ฆ ๋ง์ง๋ง for๋ฌธ์ด 1,000,000๋ถํฐ ์์ํ ์ ์์ผ๋ for๋ฌธ์ ์ต๋๊ฐ์ int๊ฐ์ ์ต๋๊ฐ์ผ๋ก ์ง์ ํด์คฌ๋ค.
728x90
๋ฐ์ํ
'๐ฅ Algorithm > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค 11399๋ฒ] ATM - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.21 |
---|---|
[๋ฐฑ์ค 1946๋ฒ] ์ ์ ์ฌ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.21 |
[๋ฐฑ์ค 16917๋ฒ] ์๋ ๋ฐ ํ๋ผ์ด๋ ๋ฐ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.21 |
[๋ฐฑ์ค 17298๋ฒ] ์คํฐ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.21 |
[๋ฐฑ์ค 4949๋ฒ] ๊ท ํ์กํ ์ธ์ - ์๋ฐ์คํฌ๋ฆฝํธ(nodejs) (0) | 2022.01.20 |
Comments