Goldbach Conjecture (Even as Sum of Two Primes)
Search for a two-prime sum of an even number with Python. Students scan only one pair direction and distinguish checking an example from proving Goldbach.
1# Helper function2def is_prime(n):3 if n < 2:4 return False5 for i in range(2, int(n ** 0.5) + 1):6 if n % i == 0:7 return False8 return True910# Take even number11num = int(input("Enter an even number (>2): "))1213# Find two primes14found = False15for i in range(2, num // 2 + 1):16 if is_prime(i) and is_prime(num - i):17 print(f"{num} = {i} + {num - i}")18 found = True19 break2021if not found:22 print("No representation found")
Output
Enter an even number (>2): 20 20 = 3 + 17
In this one
- Search complementary values
- Stop at a first solution
- Separate a check from proof
How it works
- 1
Try i from two through half the input.
- 2
Test i and num - i for primality.
- 3
Print the first successful equation and break.
Edge cases
Does the code print every valid pair?
Does the code print every valid pair?
No. It stops at the first one.
Does this prove Goldbach's conjecture?
Does this prove Goldbach's conjecture?
No. It checks only the entered case.
What's going on
The loop tries i from two through half the entered number. It checks whether both i and num - i are prime.
On the first match, the equation prints and break stops further searching. This finds one representation, not every representation or a proof of the conjecture. The prompt asks for even input above two, but the code does not validate that restriction before searching.
Does the code print every valid pair? No. It stops at the first one.
Does this prove Goldbach's conjecture? No. It checks only the entered case.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Why stop candidates near half the number?
Pick an answer to check it.
Question 2
Does the code print every valid pair?
Pick an answer to check it.
Questions people ask
Does the code print every valid pair?
No. It stops at the first one.
Does this prove Goldbach's conjecture?
No. It checks only the entered case.
Why stop candidates near half the number?
Larger choices would reverse already considered pairs.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum