View Code of Problem 27

#include<bits/stdc++.h>
using namespace std; 
int main(){
    int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		int sum=0;
		if(a>b){
			swap(a,b);
		}
			
		for(int i=a+1;i<b;i++){
			int flag=1;
			int k;
			k=(int)sqrt((double)i);//注意这个k的计算 
			for(int j=2;j<=k;j++){
				if(i%j==0){
					flag=0;
					break;
				}	
			}//判断是不是素数,不是就把flag=0 
			if(flag&&i>1)//注意1既不是素数也不是合数 
				sum+=i;	
		}
		cout << sum << endl;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 27