题意

给定闭区间[l,r] [l,r] [l,r],找出区间内满足t=a2+b2 t=a^{2}+b^{2} t=a2+b2的所有素数t t t的个数( a,b a,b a,b为任意正整数).

思路

这是一个手推很容易找出规律的数学题

听说是传说中的

费马二平方定理

  1. 除2以外的所有的素数都可以分为两类:4k + 1,4k + 3
  2. 4k + 1可以表示为2个整数的平方和,但4k + 3不行

(上面来自题解)

这道题只要判断一个质数就够了吧?%4==1符合要求

因为一开始MLE了,看了一下题解,用的bitset

#include<bits/stdc++.h>
using namespace std;
bitset <> pr;
int prime[];
int cnt,l,r;
void make()
{
pr[] = pr[] = ;
for (register int i = ; i <=r; i++)
{
if (pr[i]==) prime[++cnt] = i;
for (register int j = ; j <= cnt && i*prime[j] <= r; j++)
{
pr[i*prime[j]] = ;
if (i%prime[j] == ) break;
}
}
}
int calc(int l, int r)
{
int ans = ;
for (register int i = ; i <= r; i += )
{
if (i >= l && pr[i] == ) ++ans;
}
if (l <= && r >= ) ++ans;
return ans;
}
int main()
{
scanf("%d%d", &l, &r);
make();
printf("%d\n", calc(l, r));
return ;
}

[Codeforces113C]Double Happiness(数论)的更多相关文章

  1. cf Double Happiness(判断是否为素数且为4k+1型)

    2790. Double Happiness   time limit per test 3 seconds memory limit per test 128 megabytes input sta ...

  2. CodeForces114E——Double Happiness(素数二次筛选)

    Double Happiness On the math lesson a teacher asked each pupil to come up with his own lucky numbers ...

  3. java 开发 face++ 人脸特征识别系统

    首先要在 face++ 注册一个账号,并且创建一个应用,拿到 api key 和 api secret: 下载 java 接入工具,一个 jar 包:https://github.com/FacePl ...

  4. Codeforces 113C

    题目链接 C. Double Happiness time limit per test 5 seconds memory limit per test 128 megabytes input sta ...

  5. hdu5072 Coprime (2014鞍山区域赛C题)(数论)

    http://acm.hdu.edu.cn/showproblem.php?pid=5072 题意:给出N个数,求有多少个三元组,满足三个数全部两两互质或全部两两不互质. 题解: http://dty ...

  6. 数论 : 模运算法则(poj 1152)

    题目:An Easy Problem! 题意:求给出数的最小进制. 思路:暴力WA: discuss中的idea: 给出数ABCD,若存在n 满足 (A* n^3 +B*n^2+C*n^1+D*n^0 ...

  7. Lucas的数论题解

    Lucas的数论 reference 题目在这里> < Pre 数论分块 默认向下取整时. 形如\(\sum\limits_{i=1}^n f\left( \frac{n}{i}\righ ...

  8. UVA 10498 Happiness(线性规划-单纯形)

    Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...

  9. HDU 4497 GCD and LCM (数论)

    题意:三个数x, y, z. 给出最大公倍数g和最小公约数l.求满足条件的x,y,z有多少组. 题解:设n=g/l n=p1^n1*p2^n2...pn^nk (分解质因数 那么x = p1^x1 * ...

随机推荐

  1. logstash配置白名单决定去哪个index

    input { kafka { bootstrap_servers => "127.0.0.1:9092" client_id => "log" a ...

  2. java线程间的通信方式

    1.同步 synchronized 2.轮询 while   volatile 3.wait/notify机制 syncrhoized加锁的线程的Object类的wait()/notify()/not ...

  3. 一脸懵逼学习Hadoop中的序列化机制——流量求和统计MapReduce的程序开发案例——流量求和统计排序

    一:序列化概念 序列化(Serialization)是指把结构化对象转化为字节流.反序列化(Deserialization)是序列化的逆过程.即把字节流转回结构化对象.Java序列化(java.io. ...

  4. NetCore 生成RSA公私钥对,公钥加密私钥解密,私钥加密公钥解密

    using Newtonsoft.Json; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Encodings; using ...

  5. jxoi2017

    题解: 并不知道题目顺序就按照难度排序了 [JXOI2017]加法 这是一道很简单的贪心 最小值最大二分答案 然后我们可以从左向右考虑每一个位置 如果他还需要+A 我们就从能覆盖它的区间中挑一个最右的 ...

  6. Theorems for existence and uniqueness of variational problem

    Introduction Among simulation engineers, it is well accepted that the solution of a PDE can be envis ...

  7. Docker Client (another java docker client api)

    前一篇提到了docker-java,这里介绍另一个docker client 库,Docker Client 版本兼容 兼容17.03.1~ce - 17.12.1~ce (点 [here][1]查看 ...

  8. 【Android】Android 代码判断当前设备是否为模拟器

    [Android]Android 代码判断当前设备是否为模拟器 方法比较简单,直接粘贴代码 //判断当前设备是否是模拟器.如果返回TRUE,则当前是模拟器,不是返回FALSE public stati ...

  9. AtCoder Regular Contest 099 (ARC099) E - Independence 二分图

    原文链接https://www.cnblogs.com/zhouzhendong/p/9224878.html 题目传送门 - ARC099 E - Independence 题意 给定一个有 $n$ ...

  10. BZOJ4553/洛谷P4093 [HEOI2016/TJOI2016]序列 动态规划 分治

    原文链接http://www.cnblogs.com/zhouzhendong/p/8672434.html 题目传送门 - BZOJ4553 题目传送门 - 洛谷P4093 题解 设$Li$表示第$ ...