Search This Blog

Friday, December 17, 2010

Euler Problem 26

Difficult!!

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

Needed help with this one.. from here … thanks!!

http://universequeen.org/archives/133

____________________

 

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

            for (int d=2;d<1000;d++)
            {
                 double s = 1f/Convert.ToDouble(d);
               
                int l = reclencycle(d);

                if (l> max)
                {
                    max=l;
                    max_d=d;
                }

            }

            Console.WriteLine(max_d);
            Console.ReadLine();

        }

 

        static int reclencycle(int n)
        {
         
        int[] q = new int[1000];
        int[] r = new int[1000];
 
        r[0] = 1;
        q[0] = 0;
 
        for( int i=1; i<1000; i++ )
        {
            q[i] = r[i-1]*10/n;
            r[i] = r[i-1]*10 - q[i]*n;
 
            for( int j=1; j<i; j++ )
            {
                if( q[j] == q[i] && r[j] == r[i] )
                {
                    return (i-j);
                }
            }
 
        }
 
        return 0;
    }

No comments: