Why 3 power to n will always get a sum of digit equal to 9?

47 Views Asked by At

Why the sum of digits of $3^n$ or $(x·3)^n$ for $n \geq 2 \subset Z$, $x \geq 1 \subset Z$ always equal to 9?

For some sample cases:

$3^2 = 9$

$3^3 = 27 = 2 + 7 = 9$

$3^4 = 81 = 8 + 1 = 9$

$3^5 = 243 = 2 + 4 + 3 = 9$

$(33·3)^5 = 99^5 = 9509900499 = 9 + 5 + 0 + 9 + 9 + 0 + 0 + 4 + 9 + 9 = 54 = 5 + 4 = 9$

last9 <- c()
for(y in 1:100){
  for(i in 2:5){
    x <- y^i
    x.char <- as.character(x)
    if(grepl("^[0-9]e", x.char)){
      x.char <- paste0(gsub("e.*", "", x.char), paste0(rep(0, as.numeric(gsub(".*e", "", x.char))), collapse = ""))
    }else if(grepl(".[0-9]e", x.char)){
      x.char <- paste0(gsub("[.]|e.*", "", x.char), paste0(rep(0, as.numeric(gsub(".*e", "", x.char)) - 1), collapse = ""))
    }
    x.last <- c()
    while(nchar(x.char) > 1){
      vec <- as.numeric(unlist(strsplit(x.char, "")))
      x.char <- as.character(sum(vec))
      print(x.char)
    }
    print(x.char)
    x.last <- append(x.last, x.char)
  }
  if(all(x.last == "9")){
    last9 <- append(last9, y)
  }
}

Has run the iteration from 1 to 100 by using R, and get the results as below

last9
 [1]  3  6  9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75 78 81 84 87 90 93 96 99

Just wonder is there any proof on this? Thanks much!