-
Notifications
You must be signed in to change notification settings - Fork 5
Jungmin : Boj 6588 / Boj 10872 / Boj 1676 #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Boj 6588
에라토스테네스의 체 개념자체는 간단한데 이중루프를 돌 때 수학적인 접근을 하면 시간 복잡도를 줄일 수 있습니다. 구글에 검색해서 구현방법을 찾아보시면 좋을 것 같아요!
Boj 1676
저랑 처음에 똑같이 접근하셨네요! 저도 팩토리얼 구하고 0의 개수를 구하는 방식으로 접근했는데 계속 틀렸다고 나와서 문제를 잘 못 이해했나 싶었습니다. 시간초과가 아니라 틀렸다고 나와서 헷갈렸어요 ㅎㅎ for문으로 5의 제곱수를 구하는 방식은 새로웠습니다! 역시 여러 사람의 코드를 보면서 더욱 성장하는 것 같아요 ^^
// for(int i=2;i<=N;i++) { | ||
// targetNumbers[i] = true; | ||
// } | ||
for (int i = 2; i<=1000000; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
에라토스테네스의 체를 구현할 때 두 개의 이중 루프를 돌 때마다 i, j가 각각 2부터 100만까지 돌 필요없이
i는 2부터 100만의 제곱근까지만, j는 i * i 부터 100만까지 돌면 시간 복잡도를 줄일 수 있습니다.
for (int i = 2; i * i <= n; i++) {
if (!primes[i]) {
for (int j = i * i; j <= n ; j += i) {
primes[j] = true;
}
}
}
이런식으로요! 에라토스테네스의 체 구현 방법에 대해서 검색해보시면 도움이 되실거에요 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오....저는 배수를 확인할때 100만 * 100만 이중 반복문을 돌 필요없이 첫 반복문에서부터 제곱근까지만 돌면 시간복잡도를 줄일 수 있다고 생각했는데 차이가 없네요! 다시한번 공부해봐야겠습니다. 비교 감사합니다~^^
public class Boj_10872 { | ||
|
||
static int value = 1; | ||
public static int factorial(int n) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재귀로 구현할 때
public static int factorial(int n) {
if (n == 1) return n;
return factorial(n - 1) * n;
}
이렇게 줄여도 될 것 같습니다!
1️⃣ 골드바흐의 추측 (백준 6588)
[접근방식]
소수 구하는 로직은 '에라토스테네스의 체' 를 이용 하고
구한 소수를 가지고 브루토포스로 N값이 되는 걸 구하는 식의 로직을 구현 했지만,
시간초과가 로직 수정을 하였습니다.
2️⃣ 팩토리얼 (백준 10872)
[접근방식]
팩토리얼 공식대로 함수를 하나 만들어서 실행.
3️⃣ 팩토리얼 0의 개수 (백준 1676)
[접근방식]
문제를 잘못이해했던 부분이 있었는데, 팩토리얼해서 나온 값에서 뒤에서부터 0 갯수를 카운트하는 방법으로 문제를 설계하고 풀었는데. '틀렸습니다' 라고 떠서, 문제 이해를 잘못했다고 느껴서 찾아봤습니다.