Goldbach Conjecture (Even as Sum of Two Primes)
Express even number as sum of two primes.
AdvancedPhase 6 - Category 3: Loop & Conditional MixExample 5 of 10
goldbach-conjecture-even-as-sum-of-two-primes.py
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
What's going on
Find two primes that sum to even number.
Key Concepts:
Check if i and num-i are prime
Both must be prime
Goldbach conjecture
🔗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