Advertisement
Vickyyy01

Untitled

Jan 10th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <climits>
  3.  
  4. using namespace std;
  5.  
  6. unsigned long long Fact(unsigned long long);
  7.  
  8. int main()
  9. {
  10.     unsigned long long a, b, c;
  11.  
  12.     for(a = 1; a <= 1000; a++)
  13.     {
  14.         for(b  = 1; b <= 1000; b++)
  15.         {
  16.             for(c  = 1; c <= 1000; c++)
  17.             {
  18.                 unsigned long long product = (100*a) + (10*b) + (c);
  19.  
  20.                 if(product == (Fact(a) + Fact(b) + Fact(c)))
  21.                 {
  22.                     cout << "a = " << a << endl;
  23.                     cout << "b = " << b << endl;
  24.                     cout << "c = " << c << endl;
  25.                     cout << endl;
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
  31.  
  32. unsigned long long Fact(unsigned long long number) //factoriel algorithm function
  33. {
  34.     unsigned long long counter = 1;
  35.  
  36.     for(unsigned long long i = 1; i <= number; i++)
  37.     {
  38.         counter = counter*i;
  39.  
  40.         if(counter >= ULONG_LONG_MAX)
  41.         {
  42.             break;
  43.         }
  44.     }
  45.  
  46.     return counter;
  47. }
  48.  
  49. /*
  50. ----------------------------------------------------------------------------------------------------------------------------------
  51. ----------------------------------------------------------------------------------------------------------------------------------
  52.  
  53. Execise done based on "Algorithms: Write a computer program (or develop an algorithm) to determine whether there is a three-digit integer abc (= 100a + 10b + c) where abc = (a! + b! + c!)?"
  54.  
  55. Source: https://www.quora.com/Algorithms/Write-a-computer-program-or-develop-an-algorithm-to-determine-whether-there-is-a-three-digit-integer-abc-100a-+-10b-+-c-where-abc-a-+-b-+-c
  56.  
  57. ----------------------------------------------------------------------------------------------------------------------------------
  58. ----------------------------------------------------------------------------------------------------------------------------------
  59. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement