#include <cstdlib>
#include <iostream>
using namespace std;
bool isPrime(int prime);
int main(int argc, char *argv[])
{
int prime;
cout << "Enter an integer: ";
cin >> prime;
//bool isPrime(prime);
if (isPrime(prime)) {
cout << prime << " is a prime number." << endl;
}
else {
cout << prime << " is not a prime number." << endl;
}
//system("PAUSE");
return EXIT_SUCCESS;
}
bool isPrime(int prime){
for (int divisor = 2; divisor <=prime/2; divisor++) {
if (prime%divisor==0)
return 0;
}
return true;
}
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpib29sIGlzUHJpbWUoaW50IHByaW1lKTsKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkKeyAgIAogICAgaW50IHByaW1lOwogICAgY291dCA8PCAiRW50ZXIgYW4gaW50ZWdlcjogIjsKICAgIGNpbiA+PiBwcmltZTsKICAgIC8vYm9vbCBpc1ByaW1lKHByaW1lKTsKICAgIGlmIChpc1ByaW1lKHByaW1lKSkgewogICAgICAgY291dCA8PCBwcmltZSA8PCAiIGlzIGEgcHJpbWUgbnVtYmVyLiIgPDwgZW5kbDsKfQogICAgZWxzZSB7CiAgICAgICAgIGNvdXQgPDwgcHJpbWUgPDwgIiBpcyBub3QgYSBwcmltZSBudW1iZXIuIiA8PCBlbmRsOwogICAgICAgICB9CiAgICAvL3N5c3RlbSgiUEFVU0UiKTsKICAgIHJldHVybiBFWElUX1NVQ0NFU1M7Cn0KYm9vbCBpc1ByaW1lKGludCBwcmltZSl7CiAgICBmb3IgKGludCBkaXZpc29yID0gMjsgZGl2aXNvciA8PXByaW1lLzI7IGRpdmlzb3IrKykgewogICAgICAgIGlmIChwcmltZSVkaXZpc29yPT0wKQogICAgICAgIHJldHVybiAwOwogICAgICAgICAgIH0KICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9