Baekjoon [2061]

Kelvin 영하 273.15°C·2022년 8월 16일
1

baekjoon

목록 보기
1/1


question

This question asks to make a code that can follow this instruction:
"For number K, if one of its factors are strictly less than the required L, your program should output “BAD p”, where p is the smallest factor in K. Otherwise, it should output “GOOD”."

code:

k, l = map(int,input().split())

for i in range(2,int(l)):
    if(int(k) % i == 0):
        print("BAD", i)
        exit()
        
print("GOOD")
  1. get the inputs k and l
k, l = map(int,input().split())
  1. make a repeating function from 2 to l-1 (reason why it starts from 2 and ends in l-1 is because it doesn't include 1 and l)
for i in range(2,int(l)):
  1. use a if function to find if the k is the BAD number
    if(int(k) % i == 0):
        print("BAD", i)
        exit()

The exit() code that is used is a function that ends entire programm instead of just stopping the repearing function

  1. Lastly if nothing matches, then it means that the k and l is a GOOD number. Therefore print 'GOOD'
print("GOOD")

Thank you for reading the article!

profile
안녕하세요! python에 관한 문제들 혹은 코드등을 업로드 할 예정입니다! 관심 부탁드립니다!

0개의 댓글