Advertisement
STANAANDREY

oli 7/208 5/2/2020

Feb 5th, 2020
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define MAXVAL int(1e8)
  5. bool primes[MAXVAL];
  6. int st[MAXVAL];
  7. int top;
  8.  
  9. void precompute()
  10. {
  11.     for (int i = 2; i <= MAXVAL; i++)
  12.         primes[i] = true;
  13.  
  14.     for (int i = 2; i * i <= MAXVAL; i++)
  15.         if (primes[i])
  16.         {
  17.             for (int j = i * i; j <= MAXVAL; j += i)
  18.                 primes[j] = false;
  19.         }
  20.  
  21.     for (int i = 2; i <= MAXVAL; i++)
  22.         if (primes[i])
  23.             st[top++] = i;
  24. }
  25.  
  26. int compute_ans(int n)
  27. {
  28.     if (!n)
  29.         return 0;
  30.     if (n == 2)
  31.         return 2;//*/
  32.  
  33.     int x = 0;
  34.     while (true)
  35.     {
  36.         int temp = x;
  37.         int total = 1, it = 0;
  38.         for (int d = st[it]; d * d <= temp; d = st[++it])
  39.         {
  40.             int cnt = 0;
  41.             while (temp % d == 0)
  42.             {
  43.                 cnt++;
  44.                 temp /= d;
  45.             }
  46.             total *= (cnt + 1);
  47.         }
  48.  
  49.         if (temp != 1)
  50.             total *= 2;
  51.  
  52.         if (total == n)
  53.             return x;
  54.         x++;
  55.     }
  56. }
  57.  
  58. int main()
  59. {
  60.     int n;
  61.     cin >> n;
  62.     precompute();
  63.     cout << compute_ans(n);
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement