약수 개수 알고리즘
public static int getDivisorNumber(int n){
int count =0;
double sqrt = Math.sqrt(n);
if(sqrt%1==0){
count++;
if(n==1){
return count;
}
}
for(int i=1; i<sqrt;i++){
if(n%i==0){
count+=2;
}
}
return count;
}
어떤수가 i로 나눠질 경우 n=i*(n/i)를 이용하여 약수의 개수를 구하는 알고리즘이다. 제곱수는 같은수를 곱하여 만들어지는 수이므로 i가 sqrt(n)일 때 1만 늘려줘야 한다. 그리고 1은 약수로 1만 가지므로 약수의 개수를 셀 때 조심하여야 한다.
효율적인 약수 개수 알고리즘
https://tlrkswpcoding.tistory.com/78
약수 개수 알고리즘(java 프로그래머스 억억단을 외우자)
약수 개수 알고리즘 효율적으로 만들기 (1)이전 알고리즘 public static void getDivisorArr(int e,int[] divisorArr){ for(int i=1; i
tlrkswpcoding.tistory.com
알고리즘(귤 고르기, 억억단을 외우자)
(1)귤고르기
https://school.programmers.co.kr/learn/courses/30/lessons/138476
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
https://github.com/yougeun6021/Algorithm/blob/master/src/Level2/ChoiceTangerine.java
GitHub - yougeun6021/Algorithm
Contribute to yougeun6021/Algorithm development by creating an account on GitHub.
github.com
(2)억억단을 외우자
https://school.programmers.co.kr/learn/courses/30/lessons/138475
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
https://github.com/yougeun6021/Algorithm/blob/master/src/Level3/Memorize.java
GitHub - yougeun6021/Algorithm
Contribute to yougeun6021/Algorithm development by creating an account on GitHub.
github.com
'Java' 카테고리의 다른 글
Arrays.fill을 이용한 배열 채우기 (0) | 2022.11.28 |
---|---|
stream을 활용한 2차원배열 합 (0) | 2022.11.27 |
Sliding Window 알고리즘 (0) | 2022.11.23 |
StringBuilder를 활용한 dfs (0) | 2022.11.21 |
dfs 순열 알고리즘 (0) | 2022.11.19 |