View Code of Problem 27

#include <stdio.h>
#include <math.h>

int count(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,temp;
	long long sum;
	//输入:2个整数,0<=a,b<=65536
	while(scanf("%d %d", &a, &b)!=EOF){
		sum=0;
		//处理 
		if(a>b){
			temp=a;
			a=b;
			b=temp;
		}
		for(int i=a+1; i<b; i++){
			if(count(i)==1) sum+=i;
		}
		//输出:1个长整数 
		printf("%d\n", sum);
	}
	
}

Double click to view unformatted code.


Back to problem 27