BOJ - 1837 - 암호 제작

Updated:

import sys

def solution():
    P, K = map(int, sys.stdin.readline().split(' '))

    CHECK = [False, False] + [True] * K
    for i in range(2, K):
        if CHECK[i]:
            for j in range(2 * i, K+1, i):
                CHECK[j] = False
    primes = [i for i in range(2, K+1) if CHECK[i]]

    cnt = 0
    for i in primes:
        if P % i == 0:
            if i < K:
                print("BAD", i)
                break
            else:
                print("GOOD")
                break
        else:
            cnt += 1
            if cnt == len(primes):
                print("GOOD")

solution()

https://www.acmicpc.net/problem/1837

Categories:

Updated:

Leave a comment