본문 바로가기

프로그래머스/lv0

피자 나눠 먹기 (2)

/* 피자 나눠 먹기 (2)
 * 피자를 여섯 조각으로 잘라 줍니다.
 * 피자를 나눠먹을 사람의 수 n이 매개변수로 주어질 때,
 * n명이 주문한 피자를 남기지 않고
 * 모두 같은 수의 피자 조각을 먹어야 한다면
 * 최소 몇 판을 시켜야 하는지를 return
 *
 * n    result
 * 6    1
 * 10   5
 * 4    2
 */
 
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
public class programmer_0_40 {
    static int a1 = 6;
    static int a2 = 10;
    static int a3 = 4;
    public int solution(int n) {
        int answer = 0;
 
        while(1==1){
            answer++;
            if(answer * 6 % n == 0break;
        }
        
        return answer;
    }
    public static void main(String args[]){
        programmer_0_40 t = new programmer_0_40();
 
        System.out.println("---------------------------------------");
        System.out.println("result = " + t.solution(a1));
        System.out.println("---------------------------------------");
        System.out.println("result2 = " + t.solution(a2));
        System.out.println("---------------------------------------");;
        System.out.println("result2 = " + t.solution(a3));
        System.out.println("---------------------------------------");
    }
}
 
cs

'프로그래머스 > lv0' 카테고리의 다른 글

짝수는 싫어요  (0) 2022.12.05
피자 나눠 먹기 (1)  (0) 2022.12.05
피자 나눠 먹기 (3)  (0) 2022.12.05
배열의 평균값  (0) 2022.12.05
나이출력  (0) 2022.12.05