Tuesday, 2 September 2014

Powerful digit sum Problem 56 A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1. Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

//Answer=972
main()
{

int n=201;
int x[202];
int sum=0;
int large=0;
int a,b,k;
int y;
int hy;
for(a=1;a<100;a++)

{

for(b=1;b<100;b++)

{

      for(hy=0;hy<=n;hy++)
{
x[hy]=0;
}x[n]=a;

int g;
for(g=b;g>=1;g--)
{
for(y=n;y>=0;y--)
{
x[y]*=a;}
for(y=n;y>=0;y--)
{
    if(x[y]>9){
k=x[y];
x[y]=(k%10);
k/=10;
int ga=y;
while(k!=0)
{
x[ga-1]+=(k%10);
ga--;
k/=10;
}
}}
}
n=201;
for(y=n;y>=0;y--)
{
sum+=x[y];

}
if(sum>large){large=sum;}
sum=0;
}


}

printf("%d",large);

}





No comments:

Post a Comment