View Code of Problem 27

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

Double click to view unformatted code.


Back to problem 27