GastonFontenla

Solucionb

Nov 13th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. long long menorDivisor(long long n)
  6. {
  7.     for(long long i=2; i*i <= n; i++)
  8.         if(n%i == 0)
  9.             return i;
  10.     return n;
  11. }
  12.  
  13. int main()
  14. {
  15.     long long n, res = 0;
  16.     cin >> n;
  17.  
  18.     if(n%2)
  19.     {
  20.         n -= menorDivisor(n);
  21.         res++;
  22.     }
  23.  
  24.     res += n/2;
  25.  
  26.     cout << res << endl;
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment