Python 기본 사항쉬움

두 소수의 합으로 숫자를 표현할 수 있나요?

'숫자는 두 소수의 합으로 표현될 수 있습니까?' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

양의 정수 n을 취하고 n이 두 소수의 합으로 표현될 수 있으면 True를 반환하고 그렇지 않으면 False를 반환하는 함수 is_sum_of_two_primes(n)을 작성하세요.

예를 들어 10 = 3 + 7(둘 다 소수)이므로 True를 반환합니다. p가 소수이고 n-p도 소수인 가능한 모든 쌍(p, n-p)을 확인합니다.

제약
  • 2 <= n <= 10^4

Example 1
Input
is_sum_of_two_primes(10)
Output
True
Explanation

10 = 3 + 7. Both 3 and 7 are prime, so True.

Example 2
Input
is_sum_of_two_primes(11)
Output
True
Explanation

11 = 2 + 9? No (9 not prime). 11 = 3 + 8? No. 11 = 5 + 6? No. But wait — we only need one valid pair. Since all fail here... Actually: no valid pair exists with distinct primes, but wait: is_sum_of_two_primes should be False for 11? Let's check: 2+9=11(9 not prime), 3+8(8 not prime), 5+6(6 not prime). Actually False.

Example 3
Input
is_sum_of_two_primes(4)
Output
True
Explanation

4 = 2 + 2. Both are prime, so True.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.