Guest User

Untitled

a guest
Dec 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. bool arrayPrima[40000];
  5. int pastiPrima[5000];
  6. int prima,counter = 0, faktor = 0;
  7. long int n, num_factors, initial_n,power, loop;
  8. using namespace std;
  9. bool cekPrima(int);
  10.  
  11. int main()
  12. {
  13.    
  14.     for (int i= 2; i<=39999; i++)
  15.         {
  16.          if (arrayPrima[i] == false)
  17.              {     prima = i;
  18.                    counter++;
  19.                    arrayPrima[prima] = true;
  20.                    pastiPrima[counter] = i;
  21.                    
  22.                    while (prima < 40000)
  23.               {
  24.                      prima +=i;
  25.                      arrayPrima[prima - i] = true;
  26.               }
  27.              }
  28.          else
  29.          if (arrayPrima[i] == true)
  30.             {
  31.                            arrayPrima[i] = false;
  32.                            continue;
  33.             }
  34.                  
  35.         }
  36.        
  37.  cin >> loop;
  38.  
  39.  while(loop--)
  40.  {            
  41.              
  42.                      cin >> n;  
  43.      
  44.      
  45.        initial_n = n;
  46.        num_factors = 1;
  47.  
  48.  
  49.  
  50.        for (long int i = 1; i <= counter; ++i)
  51.        {
  52.        power = 0;
  53.        while (n % pastiPrima[i] == 0)
  54.           {
  55.            n = n / pastiPrima[i];
  56.            ++power;
  57.           }
  58.      
  59.         num_factors = num_factors * (power + 1);
  60.         }
  61.  
  62.        if (n > 1)
  63.        {
  64.         num_factors = num_factors * 2;
  65.        }
  66.  
  67.  
  68.       if (num_factors >1 && num_factors < 5)
  69.       cout << "YA" << endl;
  70.       else
  71.       cout << "TIDAK"<< endl;
  72.  
  73.                
  74.    
  75.  }
  76.  
  77.  
  78.  return 0;    
  79. }
Add Comment
Please, Sign In to add comment