codevs 1462 素数和
1462 素数和
给定2个整数a,b 求出它们之间(不含a,b)所有质数的和。
一行,a b(0<=a,b<=65536)
一行,a,b之间(不含a,b)所有素数的和。
39 1224
111390
注意没有要求a<b
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int vis[];
void sieve_method()
{
for(int i=;i<=sqrt()+0.5;i++)
{
if(!vis[i])
for(int j=i*i;j<=;j+=i)vis[j]=;
}
}
int main()
{
sieve_method();
int n,m,ans=;
scanf("%d%d",&n,&m);
if(n>m)
{
n=n+m;m=n-m;n=n-m;
}
for(int i=n+;i<m;i++)
if(!vis[i])ans+=i;
printf("%d",ans);
return ;
}
codevs 1462 素数和的更多相关文章
- codevs——1462 素数和
1462 素数和 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 给定2个整数a,b 求出它们之间(不含a ...
- 【数论】【筛法求素数】CODEVS 1462 素数和
好吧……我不会欧拉筛也就罢了…… 傻逼筛法竟然这么长时间以来 一直RE ……源头竟然是 int 爆了. #include<cstdio> #include<algorithm> ...
- Miller-Rabin算法 codevs 1702 素数判定 2
转载自:http://www.dxmtb.com/blog/miller-rabbin/ 普通的素数测试我们有O(√ n)的试除算法.事实上,我们有O(slog³n)的算法. 定理一:假如p是质数,且 ...
- codevs:1462 素数和:给定2个整数a,b 求出它们之间(不含a,b)所有质数的和。
#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main(){ i ...
- Codevs 1702 素数判定 2(Fermat定理)
1702 素数判定 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 传送门 题目描述 Description 一个数,他是素数么? 设他为P满足(P< ...
- Miller_Rabin codevs 1702 素数判定2
/* 直接费马小定理 */ #include<iostream> #include<cstdio> #include<cstdlib> #include<ct ...
- codevs 3223 素数密度
题目描述 Description 给定区间[L, R](L <= R <= 2147483647,R-L <= 1000000),请计算区间中素数的个数. 输入描述 Input De ...
- codevs 5790 素数序数
5790 素数序数(筛素数版) 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题目描述 Description 给定一个整数n,保证n为正整数且在int范 ...
- codevs——1430 素数判定
1430 素数判定 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...
随机推荐
- Eureka简介
Eureka是Spring Cloud Netfix 的一个子模块,也是核心模块之一,用于云端服务发现.一个基于RestFul的服务,用于定位服务,以实现云端中间层服务发现和中间层转移. 服务注册与发 ...
- node.js 基础篇
日志输出方式 node test.js 2>error.log 1>info.log 如果需要日志文件追加 node test.js 2>>error.log 1>> ...
- mysql处理旧数据-使用模板以及临时表,不建议直接使用本表!!
一 业务背景新版本中新建了一个项目的角色表,即每个项目都拥有几个角色,原来历史项目是没有角色的,这就要求使用脚本对表中的历史项目进行处理, 业务需求:每个项目都要有三个角色: 表 : pm_proje ...
- v8-su-root
1.下载userdebug版本 2.设置模块打开develop options 3.勾选usb debugging 4.adb remount 5.解压SuperSU_N.7z(联系我索取)并push ...
- ubuntu git 简单入门【转】
转自:http://blog.chinaunix.net/uid-20718384-id-3334859.html 1. 安装 sudo apt-get install git-core 2. 初始 ...
- Linux时间子系统之七:定时器的应用--msleep(),hrtimer_nanosleep()【转】
转自:http://blog.csdn.net/droidphone/article/details/8104433 我们已经在前面几章介绍了低分辨率定时器和高精度定时器的实现原理,内核为了方便其它子 ...
- aarch64_n2
nodejs-is-dotfile-1.0.2-2.fc26.noarch.rpm 2017-02-12 00:27 9.5K fedora Mirroring Project nodejs-is-e ...
- shell监控网站是否自动运行并自动重启【原创】
shell监控网站是否自动运行并自动重启 #!/bin/bash -T www.baidu.com ];then echo "`date` 网站访问正常!" >> /r ...
- 超简单的qps统计方法(推荐)【转】
统计最近N秒内的QPS值(包括每秒select,insert等值) mysql> select variable_name,sum(per_sec) as qps from (select st ...
- 27 Debugging Go Code with GDB 使用GDB调试go代码
Debugging Go Code with GDB 使用GDB调试go代码 Introduction Common Operations Go Extensions Known Issues Tu ...