

이번 문제는 입력된 두 수의 관계를 판단하여, 약수인지 배수인지 또는 해당되지 않는지를 조건에 따라 출력하는 문제이다.
기초적인 수학 개념인 약수와 배수의 정의를 알고 있다면 쉽게 해결할 수 있는 문제였다.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
internal class math1
{
static void Main(string[] args)
{
//백준 5086 배수와 약수
while(true)
{
string[] input = Console.ReadLine().Split();
int i = int.Parse(input[0]);
int j = int.Parse(input[1]);
if (i == 0 && j == 0)
break;
else if (j % i == 0) // b가 a의 배수라면 a는 b의 약수
{
Console.WriteLine("factor");
}
else if(i % j == 0) // a가 b의 배수라면 b는 a의 약수
{
Console.WriteLine("multiple");
}
else
{
Console.WriteLine("neither");
}
}
}
}
}

'코딩 테스트 > 백준' 카테고리의 다른 글
| 백준 - [단계별로 풀어보기 약수, 배수와 소수 1] 9506 약수들의 합 (0) | 2026.03.26 |
|---|---|
| 백준 - [단계별로 풀어보기 약수, 배수와 소수 1] 2501 약수 구하기 (0) | 2026.03.26 |
| 백준 - [단계별로 풀어보기 수학1] 1193 분수 찾기 (0) | 2026.03.25 |
| 백준 - [단계별로 풀어보기 수학1] 2869 달팽이는 올라가고 싶다 (0) | 2026.03.24 |
| 백준 - [단계별로 풀어보기 수학1] 2292 벌집 (0) | 2026.03.23 |