C D03 - Prime Testing - 3

Source Code:

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int isprime(unsigned long n)
{
    if(n==2 || n==3) return 1;
    if(n==1 || n%2==0 || n%3==0) return 0;
    for(unsigned long i=5;i<=sqrt(n);i+=6)
    {
        if(n%i==0 || n%(i+2)==0) return 0;
    }
    return 1;
}

int main() {
    unsigned long n,a;
    scanf("%lu",&n);
    while(n--)
    {
        scanf("%lu",&a);
        if(isprime(a)) printf("yes\n");
        else printf("no\n");
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    return 0;
}

Comments