자바로 백준 1145 풀기

hong030·2023년 4월 4일
0
  • 브론즈 1단계 문제

풀이)

문제: 5개의 숫자가 주어질 때, 적어도 대부분의 배수를 구하여라.

입력값 5개의 숫자는 모두 100 이하이므로 for문을 통해 1부터 answer 값까지 1씩 늘려가며 5개의 숫자로 모두 나눠보는 식으로 푼다.

내 코드)

import java.io.*;
import java.util.*;

public class Backjoon1145 {
	public static void main(String[]args) throws IOException{
		
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));		
		StringTokenizer st = new StringTokenizer(bf.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		int e = Integer.parseInt(st.nextToken());

	
		int ans = 1;
		while(true) {
			int count = 0;
			if(ans%a == 0) count ++;
			if(ans%b == 0) count ++;
			if(ans%c == 0) count ++;
			if(ans%d == 0) count ++;
			if(ans%e == 0) count ++;
			
			if(count>=3) {
				System.out.println(ans);
				break;
			}
			else
				ans++;
		}
		
	}	
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글