백준 #32369번 양파 실험

jhj·2025년 1월 17일

백준 JAVA

목록 보기
541/583
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int p = 1;
		int q = 1;
		
		for(int i = 0; i < n; i++) {			
			int temp;
			p += a;
			q += b;
			
			if(p < q) {
				temp = p;
				p = q;
				q = temp;
			}else if(p == q) {
				q = q - 1;
			}
		}
		
		System.out.println(p + " " + q);
		sc.close();
	}
}
profile
개발자를 꿈꾸는

0개의 댓글