2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?


In [34]:
open System.Numerics

let rec pow x n = 
    match n with
    | 0 -> 1 
    | _ -> x * (pow x (n-1))

let bigOne = BigInteger(1)

let rec pow' x n = 
    if n = 0 then bigOne
    else x * (pow' x (n-1))

let twoToTheOneThousand = pow' (new BigInteger(2)) 1000

twoToTheOneThousand.ToString().ToCharArray()
|> Array.map string
|> Array.map int
|> Array.sum


Out[34]:
1366

In [ ]: