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
- github lfs
- vercel git lfs
- animation
- ELECTRON
- camera permission
- github 100mb
- 티스토리 성능
- augmentedDevice
- ffi-napi
- custom printing
- Recoil
- 이미지 데이터 타입
- react-native
- dvh
- npm package
- react-native-dotenv
- adb connect
- camera access
- Failed to compiled
- Git
- adb pair
- electron-packager
- device in use
- Each child in a list should have a unique "key" prop.
- Can't resolve
- nextjs
- rolldown
- html
- silent printing
- github pdf
Archives
- Today
- Total
Bleeding edge
소수구하기 본문
본인의 이전의 수를 일일이 나눠서하는 방법을 사용하면 오래 걸리니, 에라토스테네스의 체를 활용한. (여러번봐도 이름이 어려우니 그냥 소수의 체라고 기억을 하고있...습니다) 방법을 서술하겠습니다.
1. 우선, 소수의 Boundary condition에 해당하는 1에 대한 값 (0부터는 자연수가 아니라 흠흠..)
2. 그리고 2의 배수에 관한 값
3. 나머지는 3부터 주어진 숫자의 루트값이 전에 대한 값들.
const isPrime = num => {
//Boundary Condition(1)
if (num===1) return false;
if (num%2===0) return num===2? true : false;
let sqrt = parseInt(Math.sqrt(num));
for(i=3;i<=sqrt;i++){
if(num%i===0)return false
}
return true
}
여러번 보다보니 좀 익숙해진거같다. 주의할 것, sqrt앞의 기호는 <=이다
요즘 너무, 조급하게 잘하려고 하는거같다. 예전에 공부할 때 들었던, 7번 잊어버려야 제대로 기억한다! 라는 마인드를 기억하며.. 나중에 또 까먹으면 또 보자 소수야
'코딩테스트 공부' 카테고리의 다른 글
eval() (0) | 2022.03.30 |
---|---|
최대공약수, 최소공배수 (0) | 2022.03.28 |
짝지어 제거하기-프로그래머스 js (0) | 2022.03.28 |
[짤막]charCodeAt (0) | 2022.03.23 |
순열(permutation)과 조합(combination) (0) | 2022.03.22 |