Search This Blog

Sunday, December 19, 2010

Euler Problem 30

Iterate.. split up to sep characters… power of 5 to each.. sum… is it equal to the current iteration variable.. if so.. add to the big sum.. repeat…

http://projecteuler.net/index.php?section=problems&id=30

____________

static void Main(string[] args)
        {
            int bigsum = 0;

            for (int i = 2; i < 10000000; i++)
            {

                string s = i.ToString();
                int sum = 0;

                for (int x=0;x<s.Length;x++)
                {
                    int c = Convert.ToInt32( s.Substring(x, 1));

                    sum += Convert.ToInt32(Math.Pow(c,5));
                }

                if (sum == i)
                {
                    Console.WriteLine(i);
                    bigsum += sum;
                }


            }

            Console.WriteLine(">> "+bigsum);
             Console.ReadLine();

        }

No comments: