16 - power digit sum

2^15 = 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^1000?

cevap : 1366

visual studio’da c# icin reference eklenmesi bir baska kernel turu icin burada

C# kodu asagidaki kodlara System.Numerics eklendi. using System.Numerics; satiri girildi.

// project euler problem 16
// yasin tasan --> feb 2015

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

namespace project_euler_16
{
    class Program
    {
        static void Main(string[] args)
        {
            sub_prog sub_program = new sub_prog();

            BigInteger power, sum;
            int len = 1000;

            power = BigInteger.Pow(2, len);

            sum = sub_program.sum_of_digits(power);

            Console.WriteLine("calculation length (max calculation power) = {0}", len);
            Console.WriteLine("digit sum of the result = {0}", sum);

            Console.ReadKey();
        }
    }

    partial class sub_prog
    {
        public BigInteger sum_of_digits(BigInteger number)
        {
            BigInteger sum = 0, remainder;

            while (number != 0)
            {
                remainder = number % 10;
                sum = sum + remainder;
                number = number / 10;
            }
            return sum;
        }
    }

}