Search This Blog

Saturday, December 18, 2010

Euler Problem 29

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

This is easy … IF… you can handle big numbers…. which is possible in .Net4.. or.. using a BigInteger class..

I used the CodeProject class from Chew Keong TAN

http://www.codeproject.com/KB/cs/biginteger.aspx

then ran the simple iteration as follows…

__________________

static void Main(string[] args)
       {
          
           List<BigInteger> ans = new List<BigInteger>();

           for (int a = 2; a < 101; a++)
           {
               for (int b = 2; b < 101; b++)
               {

                   BigInteger bg = pow(a, b);

                   if (!ans.Contains(bg))
                   {
                       ans.Add(bg);
                   }

               }


           }

           Console.WriteLine(ans.Count);

            Console.ReadLine();

       }


       static BigInteger pow(int a, int b)
       {
           BigInteger res = 1;

           for (int t = 1; t < b+1; t++)
           {
               res *= a;
           }

           return res;
       }

No comments: