View Code of Problem 3493

#include <stdio.h>
#include <string.h>

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

int main() {
	int a, b;
	while (scanf("%d %d", &a, &b) != EOF) {
		int count = 0;
		if (a == -1 && b == -1) {
			break;
		}
		for (int i = a;i <= b;i++) {
			if (isPrime(i)) {
				count++;
			}
		}
		printf("%d\n", count);
	}
}

Double click to view unformatted code.


Back to problem 3493