codevs:1462 素数和:给定2个整数a,b 求出它们之间(不含a,b)所有质数的和。

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int flag=0,a,b,tot=0;
scanf("%d%d",&a,&b);
if(a>b)swap(a,b);
for(int i=a+1;i<b;++i)
{
flag=1;
for(int j=2;j<=sqrt(i);++j)
{
if(i%j==0)
{
flag=0;
break;
}
}
if(flag==1)
tot+=i;
}
printf("%d",tot);
return 0;
}

posted @ 2017-03-23 20:33  快乐永恒  阅读(605)  评论(0编辑  收藏  举报