# Project Euler – Problem 46 Solution

Presently sponsored by Serverless Guru: Your guide to cloud excellence, helping you every step of your serverless journey, including team training, pattern development, mass service migrations, architecting, and developing new solutions. Speak to a Guru today.

#### Problem

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 + 2×12

15 = 7 + 2×22

21 = 3 + 2×32

25 = 7 + 2×32

27 = 19 + 2×22

33 = 31 + 2×12

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?

#### Solution

```let hasDivisor(n) =
let upperBound = int64(sqrt(double(n)))
[2L..upperBound] |> Seq.exists (fun x -> n % x = 0L)

// need to consider negative values
let isPrime(n) = if n <= 1L then false else not(hasDivisor(n))

// generate the sequence of odd composite numbers
let oddCompositeNumbers =
Seq.unfold (fun state -> Some(state, state+2L)) 9L
|> Seq.filter (fun n -> not(isPrime n))

// generate the sequence of prime numbers
let primeNumbers = Seq.unfold (fun state -> Some(state, state+2L)) 1L |> Seq.filter isPrime

// function to check if a number can be written as the sum of a prime and twice a square
let isSum(number) =