View Code of Problem 103

#include<stdio.h>
#define max 1000010
int a[max] = {};
int main() {
	for (int i = 2; i < max; i++) {
		if (a[i] == 0) {
			for (int j = i * 2; j < max; j += i) {
				a[j] = 1;
			}
		}
	}
	int m, n;
	while (scanf("%d%d", &m, &n) != EOF) {
		int sum = 0;
		for (int i = m; i <= n; i++) {
			if (a[i] == 0) {
				sum++;
			}
		}
		printf("%d\n", sum);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 103