Advertisement
Regeneric

Untitled

Nov 12th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. auto isPrime(int, int) -> bool;
  4.  
  5. auto main(int argc, char** argv) -> int {
  6. int toCheck = 0;
  7.  
  8. while(std::cin >> toCheck) {
  9. if(isPrime(toCheck, 2)) std::cout << "true" << std::endl;
  10. else std::cout << "false" << std::endl;
  11. }
  12.  
  13. return 0;
  14. }
  15.  
  16.  
  17. auto isPrime(int n, int i) -> bool {
  18. if(n <= 2) return (n == 2) ? true : false;
  19. if(!(n%i)) return false;
  20. if(i*i > n) return true;
  21.  
  22. return isPrime(n, i+1);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement