View Code of Problem 27

#include<iostream>
#include<cstdio>
#include<math.h>

using namespace std;
int prime(int x);

int main()
{
	int a, b;
	while(scanf("%d %d", &a, &b) != EOF)
	{
		long long sum = 0;
		if(a > b)
		{
			int tmp = a;
			a = b;
			b = tmp;
		}
		for(int i = a + 1; i < b; i++)
			if(prime(i))
				sum += i;
		cout << sum << endl;
	}
	return 0;
}

int prime(int x)
{
	int flag = 1;
	for(int i = 2; i <= sqrt(x); i++)
		if(x % i == 0)
		{
			flag = 0;
			break;
		}
	return flag;
}

Double click to view unformatted code.


Back to problem 27