16002. 합성수 방정식

홍범선·2023년 4월 18일
0

SW Expert Academy

목록 보기
6/18

16002. 합성수 방정식

문제

n = int(input())
    def isPrime(num):
        for i in range(2, int(num)):
            if num % i == 0:
                return False
          
        return True
    
    cnt = 3
    while True:
        if not isPrime(cnt) and not isPrime(cnt+n):
            print("#" + str(test_case) + " " + str(cnt + n) +" " +str(cnt))
            break
        cnt += 1

x - y = N은 곧 x = y + N과 같다.
즉 y = cnt라면 x = cnt + n이다.
그리고 while문을 통해 cnt, cnt + n이 isPrime인지 확인하고 아니면 출력한다.

profile
날마다 성장하는 개발자

0개의 댓글