Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <cmath>
  5.  
  6. #define ll long long
  7.  
  8. using namespace std;
  9.  
  10. bool esPrimo(const ll &n)
  11. {
  12.     ll lim = sqrt(n);
  13.  
  14.     for(ll i = 2; i <= lim; i++)
  15.         if(!(n % i))
  16.             return false;
  17.  
  18.     return true;
  19. }
  20.  
  21. int main()
  22. {
  23.     ll n, r = 0;
  24.  
  25.     cin >> n;
  26.  
  27.     if(esPrimo(n))
  28.     {
  29.         cout << "1\n";
  30.     }
  31.     else
  32.     {
  33.         for(ll i = 2; i <= sqrt(n); i++)
  34.         {
  35.             if(esPrimo(i) && (!(n % i)))
  36.             {
  37.                 r = i;
  38.  
  39.                 break;
  40.             }
  41.         }
  42.  
  43.         cout << (1 + ((n - r) / 2)) << "\n";
  44.     }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement