문제 출처: https://www.acmicpc.net/problem/1193



규칙을 찾는다.

(1/1) (1/2, 2/1) (3/1, 2/2, 1/3) (1/4, 2/3, 3/2, 4/1) (5/1, 4/2, 3/3, 2/4, 1/5) (1/6, ..

1/1을 1, 1/2를 2, 2/1을 3, 3/1을 4, 순으로 번호를 매길 때, 각 괄호의 첫 번째 번호는 1, 2, 4, 7, 11, 16, ... 이다.


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
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int X = Integer.parseInt(reader.readLine());
        int start = 1, term = 1;
        
        while(true){
            if(start <= X && X < start+term){
                for(int i=start, j=; i<start+term ; i++, j++){
                    if(i == X){
                        if(term%== 1){
                            System.out.println((term-j) + "/" + (1+j));
                            return;
                        }
                        else {
                            System.out.println((1+j) + "/" + (term-j));
                            return;
                        }
                    }
                }
            }
            else{
                start += term;
                term++;
            }
        }
    }
}
cs



'Algorithm' 카테고리의 다른 글

백준 1475번: 방 번호  (0) 2018.10.24
백준 2775번: 부녀회장이 될테야  (0) 2018.10.24
백준 2292번: 벌집  (0) 2018.10.24
백준 9020번: 골드바흐의 추측  (0) 2018.10.21
백준 4948번: 베르트랑 공준  (0) 2018.10.21

문제 출처: https://www.acmicpc.net/problem/2292



규칙찾기.

1) 1

2) 2-7  

3) 8-19:   7+1 ~  7+6*2

4) 20-37: 19+1 ~ 19+6*3

5) 38-61: 38+1 ~ 37+6*4


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
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
    
        if(N == 1){
            System.out.println("1");
            return;
        }
        
        int start = 2, end = 7, depth = 1;
        
        while(true){
            if(start <= N && N <= end){
                System.out.println(depth+1);
                break;
            }
            else {
                ++depth;
                start = end+1;
                end += 6*depth;
            }
        }
    }
}
cs


'Algorithm' 카테고리의 다른 글

백준 2775번: 부녀회장이 될테야  (0) 2018.10.24
백준 1193번: 분수찾기  (0) 2018.10.24
백준 9020번: 골드바흐의 추측  (0) 2018.10.21
백준 4948번: 베르트랑 공준  (0) 2018.10.21
백준 1929번: 소수 구하기  (0) 2018.10.21

문제 출처: https://www.acmicpc.net/problem/9020



유사 문제 참고: http://qlyh8.tistory.com/144?category=731166

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
32
33
34
35
36
37
38
39
40
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
 
public class Main {
    public static void main(String[] args) throws Exception {
        boolean[] isPrimeArr = new boolean[10001]; 
        Arrays.fill(isPrimeArr, true);
        isPrimeArr[0= false;
        isPrimeArr[1= false;
        
        for(int i=; i<=100 ++i) { // 소수 구하기
            if (isPrimeArr[i]){
                for (int j=i+i; j<=10000; j+=i)
                    isPrimeArr[j] = false;
            }
        }
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(reader.readLine());
        StringBuilder builder = new StringBuilder();
        
        for(int i=; i<N ; i++){
            int input = Integer.parseInt(reader.readLine());
            
            for(int j=0; j<input; j++){
                // 두 소수의 차이가 가장 작은 것을 출력
                int num1 = input/- j;
                int num2 = input/+ j;
                
                if(isPrimeArr[num1] && isPrimeArr[num2]) {
                    builder.append(num1).append(" ").append(num2).append("\n");
                    break;
                }
            }
        }
        
        System.out.println(builder);
    }
}
cs



'Algorithm' 카테고리의 다른 글

백준 1193번: 분수찾기  (0) 2018.10.24
백준 2292번: 벌집  (0) 2018.10.24
백준 4948번: 베르트랑 공준  (0) 2018.10.21
백준 1929번: 소수 구하기  (0) 2018.10.21
백준 2581번: 소수  (0) 2018.10.21

+ Recent posts