Project Euler #16: Power digit sum

  • + 0 comments

    In C# :

    using System; using System.Numerics;

    class Solution { static void Main(string[] args) { int t = Convert.ToInt32(Console.ReadLine());

        while (t-- > 0)
        {
            int n = Convert.ToInt32(Console.ReadLine());
    
            BigInteger pow = BigInteger.One;
    
            for (int i = 1; i <= n; i++)
            {
                pow = BigInteger.Multiply(pow, new BigInteger(2));
            }
    
            int sum = 0;
            while (pow > 0)
            {
                BigInteger d = pow % 10;
                sum += (int)d;
    
                pow /= 10;
            }
    
            Console.WriteLine(sum);
        }
    }
    

    }