fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool esPrimo(int n) {
  5. if(n == 1)
  6. return false;
  7. if(n == 2)
  8. return true;
  9. if(n % 2 == 0)
  10. return false;
  11. for(int i = 3; i * i <= n; i += 2) {
  12. if(n % i == 0)
  13. return false;
  14. }
  15. return true;
  16. }
  17.  
  18. int main(){
  19. //verificar si un numero es primo
  20. int n;
  21. cin >> n;
  22. if(esPrimo(n))
  23. cout << "Es Primo" << endl;
  24. else
  25. cout << "No es Primo" << endl;
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
No es Primo