Advertisement
Nayeemzaman

Untitled

Aug 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool isPrime(int n)
  5. {
  6.     if (n <= 1)
  7.         return false;
  8.     if (n <= 3)
  9.         return true;
  10.  
  11.     if (n % 2 == 0 || n % 3 == 0)
  12.         return false;
  13.  
  14.     for (int i = 5; i * i <= n; i = i + 6)
  15.         if (n % i == 0 || n % (i + 2) == 0)
  16.             return false;
  17.  
  18.     return true;
  19. }
  20.  
  21. // Driver Program to test above function
  22. int main()
  23. {
  24.     int num;
  25.     cin>>num;
  26.     isPrime(num) ? cout << "true\n" : cout << "false\n";
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement