Problem 16

Statement
2¹⁵ = 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¹⁰⁰⁰?

Solution
The code, in C.

#include <stdio.h>

long long int sumExp(int e){
  int i,j,a[400]={2,0};
  long long int k=0;
  for(i=1;i<e;i++){
    for(j=0;j<400;j++)
      a[j]*=2;
    for(j=1;j<400;j++){
      a[j]+=a[j-1]/10;
      a[j-1]%=10;
    }
  }
  for(i=399;i>=0;i--)
    k+=a[i];
  return k;
}

int main(void){
  printf("%lld\n",sumExp(1000));
}

Answer
1366

No tags for this post.

SPEAK / ADD YOUR COMMENT
Comments are moderated.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>