Advertisement
AquaBlitz11

Prime test

Oct 19th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.35 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool bruteForce(int n)
  5. {
  6.     if (n < 2)
  7.         return false;
  8.     for (int i = 2; i < n; i++)
  9.     {
  10.         if (n % i == 0)
  11.             return false;
  12.     }
  13.     return true;
  14. }
  15.  
  16. int main()
  17. {
  18.     int n;
  19.     cin >> n;
  20.     cout << "n is " << (bruteForce(n) ? "" : "not a ") << "prime number." << endl;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement