Problem 16
03 May 2002
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
C#
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Numerics; namespace Euler { class Program { static void Main(string[] args) { Console.WriteLine(BigInteger.Pow(2, 1000).ToString().ToCharArray().Select(x => x - '0').Sum()); Console.ReadKey(); } } }
Racket
(define (char->digit x)
(- (char->integer x)
(char->integer #\0)))
(define (problem16)
(display (apply + (map char->digit (string->list (number->string (expt 2 1000)))))))
(problem16)
'Project Euler' 카테고리의 다른 글
Project Euler Problem 18 (0) | 2012.06.03 |
---|---|
Project Euler Problem 17 (0) | 2012.06.03 |
Project Euler Problem 60 (0) | 2012.06.03 |
Project Euler Problem 59 (0) | 2012.05.29 |
Project Euler Problem 15 (0) | 2012.05.29 |