Fragen im Vorstellungsgespräch bei Bloomberg L.P.: if A! + B! + C! = ABC and A, ... | Glassdoor.de

Frage im Vorstellungsgespräch

Financial Software Developer Intern-Vorstellungsgespräch(Studentischer Bewerber) New York, NY (Vereinigte Staaten von Amerika)

if A! + B! + C! = ABC and A, B, C are single digit numbers

 , find A, B, and C.
Antwort

Antwort im Vorstellungsgespräch

2 Antworten

0

#include

int factorial (int n)
{
 int i, f = 1;
 for (i = 2; i <= n; i++) { f = f * i; }
 return f;
}

int main()
{
 int a,b,c;

 for (a=0; a < 10; a++)
  for (b=0; b < 10; b++)
   for (c=0; c < 10; c++)
    {
     int af = factorial (a);
     int bf = factorial (b);
     int cf = factorial (c);
     int sum = af + bf + cf;
     if (sum == (100*a + 10*b +c))
      {
       printf ("A = %d, B = %d, C = %d\n", a, b, c);
       return 1;
      }
    }
 return 0;
}

Daniel am 24.08.2010
3

145.
You don't need to check for 0.
You don't need to check for any number >=6 (6! = 720, therefore 6! + B! + C! will be greater than 720. Thus, ABC needs to be greater than 720. But even if we assume A = 6, the number cannot be greater than 654, assuming that there are no repetitions in the digits).
Thus, we're reduced to [1, 5].
Now, 5! + 4! + 3! = 120 + 24 + 6 = 150.
Thus, we know that the first digit of the number has to be a 1.
So we're left with just 12 combinations for B and C and 145 seems to fit pretty well :)

PS: This is under the assumption that the digits are unique.

Anonymous am 24.01.2011

Antwort oder Kommentar posten

Um dies zu kommentieren, bitte anmelden oder Konto anlegen.