View Code of Problem 27

#include<stdio.h>
#include<math.h>
int main() {
	int a,b;
	while(~scanf("%d %d",&a,&b)) {
		int i,j,temp,flag,sum=0;
		if(a>b){
			temp=a;
			a=b;
			b=temp;
		}
		for(i=a+1; i<b; i++) {
			flag=1;
			if(i==1) continue;
			for(j=2; j<=sqrt(i); j++) {
				if(i%j==0){
					flag=0;
					break;
				}		
			}
			if(flag==1)
				sum+=i;
		}
		printf("%d\n",sum);
	}
}

Double click to view unformatted code.


Back to problem 27