View Code of Problem 27

#include <stdio.h>
#include <math.h>
int sheep(int i){
	int j,k;
	k= sqrt(i);
  	if(k < 2)
          	return i;
	for(j=2; j <= k; j++)
		if(i%j == 0)
		{
			return 0;
			break;
		}
			
	return i;
}

int main(){
	int a,b,i,sum;
	while(scanf("%d%d",&a,&b)!=EOF)
	{	sum=0;
		for(i=a+1;i<b; i++)
			sum +=sheep(i);
		printf("%d\n",sum);
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 27