Skip to content

Instantly share code, notes, and snippets.

@Zircoz
Last active April 30, 2020 17:41
Show Gist options
  • Save Zircoz/ed2524b2bb7bdcbfa016a5a891902a0f to your computer and use it in GitHub Desktop.
Save Zircoz/ed2524b2bb7bdcbfa016a5a891902a0f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int isPrime(int n) {
if(n<=1) {
return 0;
}
if(n<=3) {
return 1;
}
if(n%2==0 || n%3==0) {
return 0;
}
int i=5;
while(i*i<=n){
if(n%i==0 || n%(i+2)==0) {
return 0;
}
i+=6;
}
return 1;
}
int main() {
int N;
scanf("%i", &N);
int cases[N];
for(int i=0;i<N;i++) {
scanf("%i",&cases[i]);
}
for(int case_i=0;case_i<N;case_i++) {
int resPrime = isPrime(cases[case_i]);
if(resPrime==1) {
printf("%s","yes\n");
}
else {
printf("%s","no\n");
}
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}
#import time
#start = time.localtime()
from sys import stdin, stdout
Q=int(stdin.readline())
n=list()
for i in range(0,Q):
n.append(int(stdin.readline()))
def isPrime(n) :
if (n <= 1) :
return "no"
if (n <= 3) :
return "yes"
if (n%2 == 0 or n%3 == 0) :
return "no"
i = 5
while(i*i <= n) :
if (n%i == 0 or n%(i + 2) == 0) :
return "no"
i = i + 6
return "yes"
stdout.write('\n'.join(list(map(isPrime,n))))
#end=time.localtime()
#print(end.tm_sec - start.tm_sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment