共用方式為


Interview question: find solution to x! + y! + z! = x * y * z

This blog post has moved to https://matthewvaneerde.wordpress.com/2008/08/07/interview-question-find-solution-to-x-y-z-x-y-z/

Comments

  • Anonymous
    August 07, 2008
    we can assume that a>=b>=c (if not rearrange them) for a>=5 there are not solutions as 6!=720 > aaa, hence the program below:        static void Main(string[] args)        {            int[] F = new int[6];            for (int a = 0; a < 6; a++)            {                var fa = F[a] = a==0 ? 1 : F[a-1]a;                for (int b = 0; b <= a; b++)                {                    var fb = F[b];                    for (int c = 0; c <= b; c++)                    {                        var fc = F[c];                        if (fa + fb + fc == ab*c)                            Console.WriteLine("{0} {1} {2}", a, b, c);                    }                }            }            Console.ReadLine();        } I hope you find this efficient :)

  • Anonymous
    August 08, 2008
    You nailed it.  I want to expound a little more on this in a future post.

  • Anonymous
    August 08, 2008
    My son just noticed that I should have started all loops from 1 not from 0 as abc would be zero if a or b or c is zero. It saves a bit :) The other optimisations would be: 1/ keep a*b where fb is calculated 2/ notice that except 1! all factorials are even, so all a,b,c cannot be all odd at the same time But somehow, I have a feeling that all those optimisations have not a lot of sense, bearing in mind that the whole algorithm takes couple of microseconds anyway :)

  • Anonymous
    August 08, 2008
    Follow-up here: http://blogs.msdn.com/matthew_van_eerde/archive/2008/08/08/solution-x-y-z-x-y-z.aspx

  • Anonymous
    October 02, 2009
    NOT (x+y) = not X + NOT y .... why is this ?

  • Anonymous
    October 02, 2009
    > NOT (x+y) = not X + NOT y Sorry, I don't follow.  Is this a symbolic logic question: "~(x v y) = ~x v ~y"?  If so, that's false; De Morgan's law requires flipping v to ^ and vice versa: "~(x v y) = ~x ^ ~y". If it's just a general philosophical observation, then, you go, girl.

  • Anonymous
    October 02, 2009
    The comment has been removed