글 작성자: 취업중인 피터팬
728x90

https://www.acmicpc.net/problem/5086

 

5086번: 배수와 약수

각 테스트 케이스마다 첫 번째 숫자가 두 번째 숫자의 약수라면 factor를, 배수라면 multiple을, 둘 다 아니라면 neither를 출력한다.

www.acmicpc.net

 

문제 설명

 

해당 값이 배수인지 약수인지 구별하여 출력하는 문제입니다.

 

문제 풀이

 

너무나 쉬운 문제입니다. 크게 설명하지는 않겠습니다.

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true){
            int first = sc.nextInt();
            int second = sc.nextInt();

            if(first == 0 && second == 0){
                break;
            } else if (second%first == 0) {
                System.out.println("factor");
            } else if(first%second == 0){
                System.out.println("multiple");
            }
            else{
                System.out.println("neither");
            }
        }

    }
}