码迷,mamicode.com
首页 > 其他好文 > 详细

1462 素数和 codevs

时间:2017-04-04 19:21:40      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:using   pre   size   namespace   name   hint   nbsp   names   题目   

题目描述 Description

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

输入描述 Input Description

一行,a b(0<=a,b<=65536)

输出描述 Output Description

一行,a,b之间(不含a,b)所有素数的和。

样例输入 Sample Input

39 1224

样例输出 Sample Output

111390

数据范围及提示 Data Size & Hint

注意没有要求a<b

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstdio>
 4 
 5 using namespace std;
 6 
 7 int a,b,ans;
 8 
 9 bool judge(int x)
10 {
11     for(int i=2;i*i<=x;i++)
12         if(x%i==0) return 0;
13     return 1;
14 }
15 
16 int main()
17 {
18     scanf("%d%d",&a,&b);
19     int aa=min(a,b),bb=max(a,b);
20     for(int i=aa+1;i<bb;i++)
21         if(judge(i))
22             ans+=i;
23     printf("%d",ans);
24     return 0;
25 }

 

1462 素数和 codevs

标签:using   pre   size   namespace   name   hint   nbsp   names   题目   

原文地址:http://www.cnblogs.com/Shy-key/p/6665528.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!