[백준] 5086번 배수와 약수 / Java, Python
Baekjoon Online Judge
algorithm practice
- 단계별 문제풀기
17. 정수론 및 조합론
정수론과 조합론을 배워 봅시다.
정수론과 조합론을 배워 봅시다.
Java / Python
1. 배수와 약수
배수와 약수를 배우는 문제
이번 문제는 첫번째 수가 두번째 숫자의 약수라면 factor, 배수라면 mutiple, 둘 다 아니면 neither를 출력하는 비교적 간단한 문제입니다.
- Java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int num1 = 0;
int num2 = 0;
StringTokenizer st;
while(true){
st = new StringTokenizer(br.readLine(), " ");
num1 = Integer.parseInt(st.nextToken());
num2 = Integer.parseInt(st.nextToken());
if(num1 == 0 && num2 == 0) break;
if(num2 % num1 == 0){
System.out.println("factor");
}else if(num1 % num2 == 0){
System.out.println("multiple");
}else{
System.out.println("neither");
}
}
}
}
- Python
import sys
while True:
num1, num2 = map(int, sys.stdin.readline().split())
if num1 == 0 and num2 == 0:
break
if num2 % num1 == 0:
print("factor")
elif num1 % num2 == 0:
print("multiple")
else:
print("neither")
Author And Source
이 문제에 관하여([백준] 5086번 배수와 약수 / Java, Python), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jini_eun/백준-5086번-배수와-약수-Java-Python저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)