View Code of Problem 27

#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
using namespace std;
int main() {
	int temp[65537]={0};
	temp[2]=1;
	for(int i=3;i<65537;i++){
		int flag=0;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				flag=1;
				break;
			}
		}
		if(flag==0)
			temp[i]=1;
	}
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		if(a>b)
			swap(a,b);
		int count=0;
		for(int i=a+1;i<b;i++){
			if(temp[i]==1)
				count+=i;
		}
		cout<<count<<endl;
	}
	return 0; 
}

Double click to view unformatted code.


Back to problem 27