Project Euler

Project Euler Problem 56

steloflute 2012. 5. 28. 00:01

Problem 56

07 November 2003


 

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?


 

Solution in C#

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

namespace Euler {
    static class Program {
        static long digitalSum(BigInteger value) {
            return value.ToString().Select(x => x - '0').Sum();
        }

        static void Main(string[] args) {
            var r = Enumerable.Range(1, 99).Select(a =>
                Enumerable.Range(1, 99).Select(b => digitalSum(BigInteger.Pow(a, b))).Max()).Max();
            Console.WriteLine(r);
            Console.ReadKey();
        }
    }
}

 

'Project Euler' 카테고리의 다른 글

Project Euler Problem 58  (0) 2012.05.28
Project Euler Problem 57  (0) 2012.05.28
Project Euler Problem 55  (0) 2012.05.28
Project Euler Problem 53  (0) 2012.05.28
(C#) Project Euler Utility Functions  (0) 2012.05.27