View Code of Problem 27

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

Double click to view unformatted code.


Back to problem 27