적어도 대부분의 배수 [BOJ 1145]

HyunMin Yang·2022년 8월 11일
1
post-thumbnail

Problem Solving

Baekjoon: 적어도 대부분의 배수 1145

Code:

nums = list(map(int,input().split()))
div = min(nums)
while 1:
    cnt = 0
    for i in nums:
        if div %i ==0:
            cnt +=1
    if cnt >=3:
        break
    div +=1
print(div)

We get the input of five different numbers. The 'At least most multiples' means the multiple that can be divided with at least 3 numbers.

We first get the input of 5 different numbers and than put them into a list.

nums = list(map(int,input().split()))
div = min(nums)

When we divide the multiple by the five numbers and are divisible, we add 1 to cnt.

while 1:
    cnt = 0
    for i in nums:
        if div %i ==0:
            cnt +=1

If we finished dividing the multiple by all five numbers, we compare the cnt variable to 3 and see if it is higher or equal to 3. If it is, we break out and add 1 to div.

    if cnt >=3:
        break
    div +=1
print(div)

profile
Hello World!

0개의 댓글