首页 > 其他 > 详细

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

时间:2017-03-23 21:46:30      阅读:441      评论:0      收藏:0      [点我收藏+]

#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;
}

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

原文:http://www.cnblogs.com/kuaileyongheng/p/6607156.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!