View Code of Problem 27

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int f(int n)
{
    int f=1,i;
    if(n==1) return 0;
    else if(n>1)
    {
        for(i=2;i<=sqrt((double)n);i++)
        if(n%i==0){f=0;break;}
    }
    if(f) return 1;
    else return 0;
}

int main()
{
   int n,m,i,t;
   while(scanf("%d%d",&n,&m)!=EOF)
   {

       if(n>m){t=n;n=m;m=t;}
       int s=0;
       for(i=n+1;i<m;i++)
        if(f(i))s=s+i;
       printf("%d\n",s);
   }

    return 0;
}

Double click to view unformatted code.


Back to problem 27