View Code of Problem 27

#include<bits/stdc++.h>
using namespace std;
using namespace std;
const int MAXX=100010;
bool isvi[MAXX];
void count(){
	isvi[1]=1;
	for(int i=2;i<MAXX;i++){
		isvi[i]=0;
	}
	for(int i=2;i*i<MAXX;i++){
		if(!isvi[i]){
			for(int j=i*i;j<=MAXX;j+=i){
				isvi[j]=1;
			}
		}
	}
}
int main(){
 	int a,b;
 	count();
	while(scanf("%d%d",&a,&b)!=EOF){
		long long sum=0;
		if(a>b){
			swap(a,b);
		}
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		for(int i=a+1;i<b;i++){
			if(!isvi[i]){
				sum+=i;
			}
		}
		printf("%lld\n",sum);
	}
}

Double click to view unformatted code.


Back to problem 27