View Code of Problem 27

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

Double click to view unformatted code.


Back to problem 27