题解 | #牛牛的素数和#
牛牛的素数和
http://www.nowcoder.com/practice/d748d79f68ab443482c5547d93824f50
#include <stdio.h>
int fun(int a,int b){
int sum=0,count=1;
for(int i=a;i<=b;i++){
count=1;
for(int j=2;j<i;j++){
if(i%j==0){
count=0;
break;
}
}
if(count==1) sum+=i;
}
return sum;
}
int main(){
int l,r;
scanf("%d %d",&l,&r);
printf("%d",fun(l,r));
return 0;
}
int fun(int a,int b){
int sum=0,count=1;
for(int i=a;i<=b;i++){
count=1;
for(int j=2;j<i;j++){
if(i%j==0){
count=0;
break;
}
}
if(count==1) sum+=i;
}
return sum;
}
int main(){
int l,r;
scanf("%d %d",&l,&r);
printf("%d",fun(l,r));
return 0;
}