T1462 素数和 codevs

题目描述  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 }

 

转载于:https://www.cnblogs.com/Shy-key/p/6665528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值