View Code of Problem 27

#include <stdio.h>
#include <math.h>
int iss(int n)
{
    if(n<=1)
        return 0;
    for(int i=2;i<=sqrt(n);++i)
    {
        if(n%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    int a,b;
    while(scanf("%d %d",&a,&b)!=EOF)
    {
        if(a>b)
        {
            int te=a;
            a=b;b=te;
        }
        int sum=0;
        for(int i=a+1;i<b;++i)
        {
            if(iss(i))
                sum+=i;
        }
        printf("%d\n",sum);
    }
}

Double click to view unformatted code.


Back to problem 27