View Code of Problem 27

#include<bits/stdc++.h>
using namespace std;
int isPrime(int n){
	if(n<2) return 0;
	for(int i = 2;i*i <= n;i++){
		if(n%i==0) return 0;
	} 
	return 1;
}
int main (){
	int a, b;
	while(~scanf("%d%d", &a, &b)){
		long long sum = 0;
		if(a>b) swap(a, b);
		for(int i = a+1;i < b;i++){
			if(isPrime(i)){
				sum += i;
			}
		}
		printf("%lld\n", sum);
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 27