-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import java.util.Scanner; | ||
|
||
public class Boj_10872 { | ||
|
||
static int value = 1; | ||
public static int factorial(int n) { | ||
if (n == 0) return value; | ||
value *= n ; | ||
return factorial(n-1); | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
System.out.println(factorial(sc.nextInt())); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
|
||
public class Boj_1676 { | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int n = Integer.parseInt(br.readLine()); | ||
int cnt = 0; | ||
for (int i = 5; i <= n ; i *= 5) { | ||
junggeehoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
cnt += n / i; | ||
} | ||
|
||
System.out.println(cnt); | ||
} | ||
} | ||
|
||
/* | ||
|
||
public class Main { | ||
|
||
static int value = 1; | ||
|
||
public static int factorial(int n) { | ||
if (n == 0) return value; | ||
value *= n; | ||
return factorial(n - 1); | ||
} | ||
|
||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
int N = factorial(sc.nextInt()); | ||
char [] ch = Integer.toString(N).toCharArray(); | ||
|
||
int cnt = 0; | ||
for (int i = ch.length-1; i > 0; i--) { | ||
if (ch[i] == '0') cnt++; | ||
else break; | ||
} | ||
System.out.println(cnt); | ||
} | ||
} | ||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import java.io.*; | ||
import java.util.Arrays; | ||
|
||
|
||
public class Boj_6588 { | ||
static boolean [] targetNumbers; | ||
public static void isPrime() { | ||
targetNumbers = new boolean[1000001]; | ||
|
||
Arrays.fill(targetNumbers, true); | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. 에라토스테네스의 체를 구현할 때 두 개의 이중 루프를 돌 때마다 i, j가 각각 2부터 100만까지 돌 필요없이
이런식으로요! 에라토스테네스의 체 구현 방법에 대해서 검색해보시면 도움이 되실거에요 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 오....저는 배수를 확인할때 100만 * 100만 이중 반복문을 돌 필요없이 첫 반복문에서부터 제곱근까지만 돌면 시간복잡도를 줄일 수 있다고 생각했는데 차이가 없네요! 다시한번 공부해봐야겠습니다. 비교 감사합니다~^^ |
||
// 이미 확인된 건 넘기기 | ||
if (!targetNumbers[i]) continue; | ||
// 배수 출발. | ||
for (int j = i * 2; j <= 1000000; j += i ) targetNumbers[j] = false; | ||
} | ||
} | ||
public static void main(String[] args) throws IOException { | ||
|
||
|
||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | ||
isPrime(); | ||
while (true) { | ||
int n = Integer.parseInt(br.readLine()); | ||
if (n == 0) break; | ||
|
||
int primeNum = Integer.MIN_VALUE; | ||
for (int i = 2; i <= n/2; i++) { | ||
if (targetNumbers[i] && targetNumbers[n-i]) { | ||
primeNum = i; | ||
break; | ||
} | ||
} | ||
|
||
if (primeNum > 0) bw.write(n + " = " + primeNum + " + " + (n-primeNum) + "\n"); | ||
else bw.write("Goldbach's conjecture is wrong.\n"); | ||
} | ||
bw.flush(); | ||
bw.close(); | ||
br.close(); | ||
} | ||
} | ||
|
||
|
||
/* | ||
|
||
시간 초과. | ||
|
||
public class Main { | ||
public static String isPrime(int n) { | ||
ArrayList<Integer> list = new ArrayList<>(); | ||
boolean [] prime = new boolean[n+1]; | ||
Arrays.fill(prime, true); | ||
prime[0] = prime[1] = false; | ||
for (int i = 2; i <= Math.sqrt(prime.length); i++) { | ||
if (prime[i]) { | ||
for (int j = i*i; j <= n; j+=i) prime[j] = false; | ||
} | ||
} | ||
for (int i = 2; i < n; i++) { | ||
if (true == prime[i]) { | ||
list.add(i); | ||
} | ||
} | ||
for (int i = 0; i < list.size(); i++) { | ||
for (int k = i; k < list.size(); k++) { | ||
if (list.get(i)+list.get(k) == n) { | ||
return n + " = " + list.get(i) + " + " + list.get(k); | ||
} | ||
} | ||
} | ||
return "Goldbach's conjecture is wrong."; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int stop = 1; | ||
while (stop != 0) { | ||
stop = Integer.parseInt(br.readLine()); | ||
if (stop!=0) { | ||
System.out.println(isPrime(stop)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public class Programmers_42840 { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
|
||
public class Programmers_42839 { | ||
|
||
static HashSet<String> hs = new HashSet<>(); | ||
|
||
public static void recur(String candidate, String remain) { | ||
// base case 라고 불림. | ||
if (!candidate.equals("")) hs.add(candidate); | ||
for (int i = 0; i < remain.length(); i++){ | ||
recur(candidate + remain.charAt(i), remain.substring(0, i) + remain.substring(i+1)); | ||
} | ||
} | ||
|
||
public static boolean isPrime(int n) { | ||
// 0, 1 는 제외 | ||
if (n < 2) return false; | ||
// true = 소수, false = 합성수 | ||
boolean [] prime = new boolean[n+1]; | ||
Arrays.fill(prime, true); | ||
|
||
prime[0] = prime[1] = false; | ||
for (int i = 2; i*i <= n; i++) { | ||
// 소수가 아니라면? | ||
if (prime[i]) { | ||
for (int j = i*i; j <= n; j+=i) prime[j] = false; | ||
} | ||
} | ||
return prime[n]; | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
String str = br.readLine(); | ||
|
||
recur("", str); | ||
int cnt = 0; | ||
|
||
for (String s : hs) { | ||
if (isPrime(Integer.parseInt(s))) | ||
cnt++; | ||
} | ||
|
||
System.out.println(cnt); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class Programmers_42842 { | ||
|
||
public static int [] solution(int brown, int yellow) { | ||
/* | ||
int a = brown/2 + 2; | ||
int b = yellow + brown; | ||
|
||
double alpha = (a+Math.sqrt(a*a - 4*b)) / 2; | ||
double beta = a - alpha; | ||
|
||
int [] answer = {(int) alpha, (int) beta}; | ||
*/ | ||
|
||
int[] answer = new int[2]; | ||
|
||
for(int i = 1; i <= yellow; i++) { | ||
if(yellow % i == 0) { | ||
if(2 * i + (2 * yellow / i) == brown - 4) { | ||
answer[0] = i + 2; | ||
answer[1] = yellow / i + 2; | ||
} | ||
} | ||
} | ||
return answer; | ||
} | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
String [] ch = br.readLine().split(" "); | ||
int b = Integer.parseInt(ch[0]); | ||
int y = Integer.parseInt(ch[1]); | ||
|
||
System.out.println(solution(b,y)[0] +" " + solution(b,y)[1]); | ||
} | ||
} |
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.
재귀로 구현할 때
이렇게 줄여도 될 것 같습니다!