View Code of Problem 27

#include<bits/stdc++.h>      
using namespace std;
void show(int,int );
void find();
bool pri[100000] = {0};
int op[100000] = { };
int main(){
	int a ,b,sum = 0,t;
	find();
	while(scanf("%d%d",&a,&b)!=EOF){
		if(a > b){
			t = a;
			a = b;
			b = t;
		}
		show(a,b);
	}
	return 0;
}
void show(int a,int b){
	long long k = 0;
	for(int i = a + 1;i < b;i++ ){
		if(op[i]!=0)k+=i;
}			
	printf("%lld\n",k);
}
void find(){
	for(int i = 2;i<=65540;i++){
		if(pri[i]==false){
			op[i] = i;
			for(int j = i*2;j<=65540;j+=i){
				pri[j] = true;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 27