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,>
using System;
namespace project_euler
{
class Program
{
static void Main()
{
//Problem 56
DateTime start = DateTime.Now;
int max = 0,number=0,power=0;
for (int i = 99; i >90; i--)
{
BigInt n = i;
for (int k = 2; k <100; k++)
{
n *= i;
string s = n.ToString();
int sum = 0;
foreach (char c in s)
sum += int.Parse(c.ToString());
if (sum > max)
{
max = sum;
number = i;
power = k;
}
}
}
Console.WriteLine(max+" "+number+" to the "+power+" power");
TimeSpan time = DateTime.Now - start;
Console.WriteLine("This took {0}", time);
Console.ReadKey();
}
}
}
No comments:
Post a Comment