Codeforces 113C
C. Double Happinesstime limit per test5 seconds
memory limit per test128 megabytes
inputstandard input
outputstandard output
On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as:
t = a2 + b2, where a, b are arbitrary positive integers.
Now, the boys decided to find out how many days of the interval [l, r] (l ≤ r) are suitable for pair programming. They decided that the day i (l ≤ i ≤ r) is suitable for pair programming if and only if the number i is lucky for Peter and lucky for Bob at the same time. Help the boys to find the number of such days.
InputThe first line of the input contains integer numbers l, r (1 ≤ l, r ≤ 3·108).
OutputIn the only line print the number of days on the segment [l, r], which are lucky for Peter and Bob at the same time.
Sample test(s)input3 5output1input6 66output7
/*************************************************************************
> File Name: 113C.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月20日 星期日 13时34分53秒
> Propose:
************************************************************************/ #include <cmath>
#include <string>
#include <bitset>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; const int maxn = 1e8+1e8+1e8;
bitset<maxn> p; int
main(void) {
int L, R;
scanf("%d %d\n", &L, &R);
p.set();
for (int i = ; i*i <= R; i+=) if (p[i]) for (int j = i*i; j <= R; j+=*i) p[j] = false;
int ans = ;
for (int i = ; i <= R; i+=) if (p[i] && i >= L) ans++;
ans += (L <= && R >= ) ? : ;
printf("%d\n", ans); return ;
}
Codeforces 113C的更多相关文章
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
随机推荐
- PAT甲级——A1005 Spell It Right
题目描述 Given a non-negative integer N, your task is to compute the sum of all the digits of N, and out ...
- 【牛客挑战赛31D】 雷的打字机
题目 首先看到这个出现长度至少为\(2\)的回文子串 这就等价于不能出现两个连续且相同的字符 于是我们用概率生成函数来搞 设\(g_i\)表示\(i\)次操作后游戏没有结束的概率,\(f_{i,j}\ ...
- Luogu P3558 [POI2013]BAJ-Bytecomputer(线性dp)
P3558 [POI2013]BAJ-Bytecomputer 题意 给一个只包含\(-1,0,1\)的数列,每次操作可以让a[i]+=a[i-1],求最少操作次数使得序列单调不降.若无解则输出BRA ...
- Linux下使用SSH命令行传输文件到远程服务器
目标:CentOS 7 调整 home分区 扩大 root分区 总体过程: 把/home内容备份,然后将/home文件系统所在的逻辑卷删除,扩大/root文件系统,新建/home ,恢复/home内容 ...
- 后缀数组(SA)及height数组
最近感觉自己越来越蒟蒻了--后缀数组不会,费用流不会-- 看着别人切一道又一道的题,我真是很无奈啊-- 然后,我花了好长时间,终于弄懂了后缀数组. 后缀数组是什么? 后缀SASASA数组 给你一个字符 ...
- ajaxfileupload 上传使用demo
1.添加js引用 <script src="JS/jquery-1.4.2.min.js" type="text/javascript"></ ...
- CF 981C Useful Decomposition
题面 题目大意 给定一棵树,要求划分出几条链,使这几条链交于一点. 解题思路 因为所有链都要交于一点,所以必须交于一个度数最多的点.这样就形成了一个菊花形.然后从这个点出发到它的子树,判断子树的度数是 ...
- utils04_搭建私有Git服务器
1.远程仓库实际上和本地仓库没啥不同,纯粹为了7x24小时开机并交换大家的修改.GitHub就是一个免费托管开源代码的远程仓库.但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给G ...
- tinyproxy 反向代理无法上网原因
今天参照网上教程在服务器安装并配置了tinyproxy反向代理,此次安装反向代理的目的主要是通过内网连接上服务器,再使用服务器作为中转站进行上网.安装并启动的主要步骤如下 下载并安装tinypro ...
- PowerDesigner在修改表的字段Name的时Code不自动跟着变的处理方法以及导入Mysql数据库的表
tools-> GeneralOptions-> Dialog:Operation Modes: 去掉 NameToCodeMirroring 前面的√ 导入数据库中的表到PowerD ...