题目链接

C. Double Happiness
time limit per test

5 seconds

memory limit per test

128 megabytes

input

standard input

output

standard 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.

Input

The first line of the input contains integer numbers l, r (1 ≤ l, r ≤ 3·108).

Output

In 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)
input
3 5
output
1
input
6 66
output
7
关于bitset的使用,可以看这里关于高斯整数,可以点这里

 /*************************************************************************
> 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的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. java单元测试小结

    1. mock 构造函数 import static org.junit.Assert.*; import java.util.ArrayList; import org.junit.Test; im ...

  2. 《DSP using MATLAB》Problem 8.31

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  3. Python学习day43-数据库(多表关系)

    figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...

  4. C#墨攻IOC[转]

    原文叫看<墨攻>理解IOC概念 2006年多部贺岁大片以让人应接不暇的频率纷至沓来,其中张之亮的<墨攻>算是比较出彩的一部,讲述了战国时期墨家人革离帮助梁 国反抗赵国侵略的个人 ...

  5. 【转】 解释下浏览器是如何判断元素是否匹配某个 CSS 选择器?

    先产生一个元素集合,然后从后往前判断: 浏览器先产生一个元素集合,这个集合往往由最后一个部分的索引产生(如果没有索引就是所有元素的集合).然后向上匹配,如果不符合上一个部分,就把元素从集合中删除,直到 ...

  6. bootstrab table+表格 select可编辑完整实例

    先看下效果图: ============================================================================================ ...

  7. sqlserver数据往别的数据库迁移

    背景:sqlserver数据库数据是服务于一个.net项目.后来由于去.net 要将数据前往高斯数据库 或者Oracle. 问题是 当sql Name Age Gender from student ...

  8. 入门servlet:request获取请求行数据

    /** * 演示Request对象获取请求行数据 */ @WebServlet("/test") public class RequestDemo1 extends HttpSer ...

  9. 关于在静态html中实现语言切换的思路与实现

    在项目中只用到了三种语言:英文.中文简体.中文繁体.所以我首先想到了最笨的方法:1.直接将三种语言写在html中,显示当前设置的语言隐藏其它两种来实现.2.使用css伪元素的content:attr( ...

  10. 只要三步!阿里云DLA帮你处理海量JSON数据

    概述 您可能有大量应用程序产生的JSON数据,您可能需要对这些JSON数据进行整理,去除不想要的字段,或者只保留想要的字段,或者仅仅是进行数据查询. 那么,利用阿里云Data Lake Analyti ...