SHARE
TWEET

dsa

a guest Feb 17th, 2020 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int index = 1;
  6. int* primesArray;
  7. const int sizeOfArray = 26;
  8.  
  9. void Init()
  10. {
  11.     primesArray = new int[sizeOfArray] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
  12. }
  13.  
  14. void Print()
  15. {
  16.     for (int i = 0; i < sizeOfArray; i++)
  17.     {
  18.         cout << primesArray[i] << " ";
  19.     }
  20.     cout << endl;
  21. }
  22.  
  23. bool CheckForPrimes(int value)
  24. {
  25.     for (int i = 0; i < sizeOfArray; i++)
  26.     {
  27.         if (primesArray[i] == value)
  28.         {
  29.             return true;
  30.         }
  31.     }
  32.     return false;
  33. }
  34.  
  35.  
  36. void DeconstructionToPrimes(int inputA)
  37. {
  38.     if (CheckForPrimes(inputA))
  39.     {
  40.         cout << inputA << "";
  41.         return;
  42.     }
  43.    
  44.     int temp = inputA;
  45.     for (int i = 0; i < sizeOfArray; i++)
  46.     {
  47.         if (temp % primesArray[i] == 0 && temp / primesArray[i] >= 1)
  48.         {
  49.             int tempB = temp / primesArray[i];
  50.  
  51.             cout << primesArray[i] << "*";
  52.             DeconstructionToPrimes(tempB);
  53.             //cout << primesArray[i] << "+";
  54.  
  55.             temp = temp % primesArray[i];
  56.         }
  57.     }
  58. }
  59.  
  60. int main()
  61. {
  62.     Init();
  63.     Print();
  64.  
  65.     cout << "Deconstruction of " << 162 << ": ";
  66.     DeconstructionToPrimes(162);
  67.  
  68.     //12 = 2 . 6 = 2 . 2 . 3
  69.     //20 = 2 . 10 = 2 . 2 . 5
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top