Goldbach's marginal conjecture - Write integer as sum of three primes - MATLAB Cody - MATLAB Central

Problem 44403. Goldbach's marginal conjecture - Write integer as sum of three primes

Difficulty:Rate

Goldbach's strong conjecture states that every even integer greater than 2 can be expressed as the sum of two primes. For example: 4 = 2+2, 6 = 3+3, 8 = 3+5, 10 = 3+7 = 5+5, 12 = 5+7 etc.

As a corrollary, Goldbach's weak conjecture states that every odd integer greater than 7 can be expressed as the sum of three odd primes. For example: 9 = 3+3+3, 11 = 3+3+5, 13 = 3+3+7 = 3+5+5, 15 = 3+5+7 = 5+5+5 etc.

A third conjecture was written by Goldbach in the margin of a letter, and (in its modern version) states that

" Every integer greater than 5 can be expressed as the sum of three primes. "

Examples:

  • 6 = 2 + 2 + 2
  • 7 = 2 + 2 + 3
  • 8 = 2 + 3 + 3
  • 9 = 2 + 2 + 5 = 3 + 3 + 3
  • 10 = 2 + 3 + 5
  • 11 = 2 + 2 + 7 = 3 + 3 + 5
  • 12 = 2 + 3 + 7 = 2 + 5 + 5
  • 13 = 3 + 3 + 7 = 3 + 5 + 5
  • 14 = 2 + 5 + 7
  • 15 = 2 + 2 + 11 = 3 + 5 + 7 = 5 + 5 + 5

Your task is to write a function which takes a positive integer n as input, and which returns a 1-by-3 vector y, which contains three numbers that are primes and whose sum equals n. If there exist multiple solutions for y, then any one of those solutions will suffice. However, y must be in sorted order. You can assume that n will be an integer greater than 5.

Solution Stats

51.37% Correct | 48.63% Incorrect
Last Solution submitted on Feb 13, 2025

Problem Comments

Solution Comments

Show comments

Group

Algorithm I Image
Algorithm I
  • 17 Problems
  • 5 Finishers

Problem Recent Solvers67

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page