View Code of Problem 27

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
	int a,b,i,j,k,temp;
	while(scanf("%d %d",&a,&b)!=EOF){
		long int sum=0;
		if(a>b){
			temp=a;
			a=b;
			b=temp;
		}
		for(i=a+1;i<b;i++){
			k=sqrt(i);
			for(j=2;j<=k;j++){
				if(i%j==0){
					break;
				}	
			}
				if(j>k){
					sum=sum+i;
				}
		
		}
		printf("%ld\n",sum);
	}
}

Double click to view unformatted code.


Back to problem 27