#include <stdio.h>
#include <math.h>
int main() {
int num, i, is_prime = 1;
// Asking user to input a number
printf("Enter a positive integer: ");
if (num <= 1) {
is_prime = 0; // Numbers less than or equal to 1 are not prime
} else {
// Loop to check divisibility
for (i
= 2; i
<= sqrt(num
); i
++) { if (num % i == 0) {
is_prime = 0; // If divisible, not prime
break;
}
}
}
if (is_prime) {
printf("%d is a prime number.\n", num
); } else {
printf("%d is not a prime number.\n", num
); }
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIGludCBudW0sIGksIGlzX3ByaW1lID0gMTsKCiAgICAvLyBBc2tpbmcgdXNlciB0byBpbnB1dCBhIG51bWJlcgogICAgcHJpbnRmKCJFbnRlciBhIHBvc2l0aXZlIGludGVnZXI6ICIpOwogICAgc2NhbmYoIiVkIiwgJm51bSk7CgogICAgaWYgKG51bSA8PSAxKSB7CiAgICAgICAgaXNfcHJpbWUgPSAwOyAvLyBOdW1iZXJzIGxlc3MgdGhhbiBvciBlcXVhbCB0byAxIGFyZSBub3QgcHJpbWUKICAgIH0gZWxzZSB7CiAgICAgICAgLy8gTG9vcCB0byBjaGVjayBkaXZpc2liaWxpdHkKICAgICAgICBmb3IgKGkgPSAyOyBpIDw9IHNxcnQobnVtKTsgaSsrKSB7CiAgICAgICAgICAgIGlmIChudW0gJSBpID09IDApIHsKICAgICAgICAgICAgICAgIGlzX3ByaW1lID0gMDsgLy8gSWYgZGl2aXNpYmxlLCBub3QgcHJpbWUKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGlmIChpc19wcmltZSkgewogICAgICAgIHByaW50ZigiJWQgaXMgYSBwcmltZSBudW1iZXIuXG4iLCBudW0pOwogICAgfSBlbHNlIHsKICAgICAgICBwcmludGYoIiVkIGlzIG5vdCBhIHByaW1lIG51bWJlci5cbiIsIG51bSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=