# ProjectEuler-Problem 46

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**YGC**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.

9 = 7 + 21^{2}

15 = 7 + 22^{2}

21 = 3 + 23^{2}

25 = 7 + 23^{2}

27 = 19 + 22^{2}

33 = 31 + 21^{2}

It turns out that the conjecture was false.

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

—————-

Referring to http://learning.physics.iastate.edu/hodges/mm-1.pdf, this problem is very famous.

Using brute-force is the solution I can only think of. Surprisingly, it turns out very fast.

^{?}View Code RSPLUS

1 2 3 4 5 6 7 8 9 10 11 12 13 14 | require(gmp) n <- 1:10000 p <- n[as.logical(isprime(n))] for (i in seq(3,10000,2)) { if (any(p==i)) next x <- sqrt((i-p[p |

### Related Posts

To

**leave a comment**for the author, please follow the link and comment on their blog:**YGC**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.