\[2^{15} = 32768\]

The sum of the digits for 32768 is:

3 + 2 + 7 + 6 + 8
## [1] 26

What is the sum of the digits of the number \(2^{1000}\)?

That is a rather large number, larger than R is able to handle on its own.

We load the gmp package that can handle very large numbers:

library(gmp)
## 
## Attaching package: 'gmp'
## The following objects are masked from 'package:base':
## 
##     %*%, apply, crossprod, matrix, tcrossprod
large_number <- as.bigz(2)^as.bigz(1000)

convert it to a character

large_character <- as.character(large_number)

Split it in individual characters:

large_character_vector <- strsplit(large_character, "")

That is a list, so we subset the first (and only) element, coerce it to numeric, and sum all the numbers:

answer <- sum(as.numeric(large_character_vector[[1]]))