This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int is_prime(long long int n) | |
{ | |
long long int i; | |
/* | |
if(n<2) { | |
return 0; | |
} | |
*/ | |
if(n == 2) { | |
return 1; | |
} | |
if(n % 2 == 0) { | |
return 0; | |
} | |
for(i = 3; i < sqrt(n); i = i + 2) { | |
if(n % i == 0) { | |
return 0; | |
} | |
} | |
return 1; | |
} | |
int main() | |
{ | |
long long int n, run; | |
scanf("%lld\n",&run); | |
while(run--) | |
{ | |
scanf("%lld", &n); | |
if(1 == is_prime(n)) { | |
printf("%lld is a prime\n", n); | |
} | |
else { | |
printf("%lld is not a prime\n", n); | |
} | |
} | |
return 0; | |
} |
Comments
Post a Comment