View Code of Problem 27

#include <stdio.h>
#include <math.h>
using namespace std;
int main(){
	long long int a,b;
	long long int sum = 0;
	int flag=1;
	while( ~scanf("%lld%lld", &a, &b )){
		sum = 0;
		for( int i = a+1; i<b; i++ ){
			flag = 1;
			for( int j=2; j<=sqrt(i); j++){
				if( i%j == 0 ){
					flag =0;
					break;
				}
			}
			if( flag == 1) sum += i;
			else continue;
		}
		printf("%lld\n", sum );
	}
	return 0;
	
}

Double click to view unformatted code.


Back to problem 27