Advertisement
mateuspl

URI: 1602 - Hiperprimos

Feb 7th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. const int MAX = 10e6;
  7.  
  8. bool prime[MAX + 1];
  9. int divisors[MAX + 1];
  10.  
  11. int main()
  12. {
  13.     memset(&prime, true, sizeof(bool) * (MAX + 1));
  14.     memset(&divisors, 0, sizeof(int) * (MAX + 1));
  15.  
  16.     for (int i = 2; i <= MAX; i++)
  17.     {
  18.         if (prime[i])
  19.         {
  20.             divisors[i] = 2;
  21.  
  22.             for (int j = i + i; j <= MAX; j += i)
  23.             {
  24.                 divisors[j] += 1 + divisors[j / i];
  25.                 prime[j] = false;
  26.             }
  27.         }
  28.     }
  29.  
  30.     int hiperprimes = 0;
  31.  
  32.     for (int i = 2; i <= MAX; i++)
  33.         divisors[i] = prime[divisors[i]] ? ++hiperprimes : hiperprimes;
  34.  
  35.     int n;
  36.     while (cin >> n)
  37.         cout << divisors[n] << endl;
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement