C D01 - Prime Testing - 1

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() {

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

Comments