View Code of Problem 27

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;
int a[65536] = {};
int b[10000] = {};
void prime(int a[]) {
	int k = 0;
	for (int i = 2; i < 65536; i++) {
		if (a[i] == 0) {
			b[k++] = i;
			for (int j = i + i; j < 65536; j+=i) {
				a[j] = 1;
			}
		}
	}
}
int main() {
	int n, m;
	prime(a);
	while (scanf("%d%d", &n, &m) != EOF) {
		int sum = 0;
		int i = 0;
		if (n > m) {
			int t = n;
			n = m;
			m = t;
		}
		while(1) {
			if (b[i] >= m) {
				break;
			}
			if (b[i] > n) {
				sum += b[i];
			}			
			i++;
		}
		printf("%d\n", sum);
	}
}

Double click to view unformatted code.


Back to problem 27