Facebook
From Silly Bongo, 7 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 252
  1. /**
  2. * Zlicza czynniki pierwsze liczby
  3. * @param iValue liczba sprawdzana
  4. * @return iCont liczba pierwszych
  5. */
  6. int ifun_CountPrime(int iValue) {
  7.         int iK = 2, iCount = 0;
  8.        
  9.         while (iValue>1) {
  10.                 while (iValue%iK == 0){
  11.                         iCount++;
  12.                         iValue /= iK;
  13.                 }
  14.                 iK++;
  15.         }
  16.        
  17.         return iCount;
  18. }
  19.  
  20. /**
  21. * Wypelnia tablice dzielnikami pierwszymi liczby
  22. * @param iValue liczba
  23. * @return iPrimeNumbersTab wypelniona tablica
  24. */
  25. int *ifun_PrimeNumbers(int iValue) {
  26.         int iSize = ifun_CountPrime(iValue);
  27.         int *iPrimeNumbersTab = ifun_MakeTab(iSize);
  28.         int g = sqrt(iValue);
  29.  
  30.         for (int i = 2, j=0; i <= g; i++) {
  31.                 while (iValue % i == 0)
  32.                 {
  33.                         iPrimeNumbersTab[j] = i;
  34.                         iValue /= i;
  35.                         j++;
  36.                 }
  37.         }
  38.         return iPrimeNumbersTab;
  39. }
  40.