View Code of Problem 27

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

Double click to view unformatted code.


Back to problem 27