Problem Description

Euler is a well-known matematician, and, among many other things, he discovered that the formula
n^{2} + n + 41n2+n+41 produces a prime for 0 ≤ n &lt; 400≤n<40. For n = 40n=40, the formula produces 16811681, which is 41 ∗ 4141∗41.Even though this formula doesn’t always produce a prime, it still produces a lot of primes. It’s known that for n ≤ 10000000n≤10000000, there are 47,547,5% of primes produced by the formula! So, you’ll write a program that will output how many primes does the formula output for a certain interval.

Input

Each line of input will be given two positive integer aa and bb such that 0 ≤ a ≤ b ≤ 100000≤a≤b≤10000. You must read until the end of the file.

Output

For each pair a, ba,b read, you must output the percentage of prime numbers produced by the formula in
this interval (a ≤ n ≤ b)(a≤n≤b) rounded to two decimal digits.

Sample Input

0 39
0 40
39 40

Sample Output

100.00
97.56
50.00

题意:

输入数据a和b,求a和b之间数经过n^{2}+n+41n2+n+41为素数的所占比值保留两位小数;

思路:

数据范围00 到 1000010000啊~~~, 懂 !!!!!!!! _(:зゝ∠)_而且卡精度卡到死10^{-6}10−6真***恶心~~~~(>—<)~~~~;

主要进行素数打表(这是关键)o(︶︿︶)o 唉(在这上面错了N次)不说了,说多了都是泪φ(≧ω≦*)♪;

看代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define ll long long
const int N=;
bool isprime[N];
bool Prime(int a)//判定素数
{
for(int i=; i*i<=a; i++)
if(a%i==)
return false;
return true;
}
void Isprime()//进行打表
{
for(int i=; i<N; i++)
{
if(Prime(i*i+i+))
isprime[i]=true;
else
isprime[i]=false;
}
}
int main()
{
Isprime();
int a,b;
while(cin>>a>>b)
{
int s=;
for(int i=a; i<=b; i++)
{
if(isprime[i])
s++;//记录个数;
}
double z=(double)s/(double)(b-a+)*+0.00000001;//卡精度
printf("%.2lf\n",z);
}
return ;
}

实践是检验真理的唯一标准

Prime Time UVA - 10200(精度处理,素数判定)的更多相关文章

  1. 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板

    题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b  求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优 ...

  2. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  3. 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429

    素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...

  4. 10^9以上素数判定,Miller_Rabin算法

    #include<iostream> #include<cstdio> #include<ctime> #include<string.h> #incl ...

  5. HDU2138 素数判定

    HDU2138 给定N个32位大于等于2的正整数 输出其中素数的个数 用Miller Rabin 素数判定法 效率很高 数学证明比较复杂,略过, 会使用这个接口即可. #include<iost ...

  6. codevs——1430 素数判定

    1430 素数判定  时间限制: 1 s  空间限制: 1000 KB  题目等级 : 青铜 Bronze 题解       题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...

  7. [算法]Miller-Robbin素数判定

    目录 一.实现原理 二.应用 判断一个正整数是否为素数 三.小结 一.实现原理 我们以前都是怎么判断素数的呢: 试除法: 若一个正整数N为合数,则存在一个能整除N的数k,其中\(2\leqslant ...

  8. HDOJ2012素数判定

    素数判定 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  9. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

随机推荐

  1. vue+elementui 开发的网站IE浏览器加载白屏(不兼容)解决办法

    1.需要检查一下 export default { name: 'aa',-------vue的name是不可以重复的-----这个是决定性原因 data() { return {} } 2.变量声明 ...

  2. Mac cpu过高问题分析及解决

    1.mds.mds_stores.mdworker 关闭: sudo mdutil -a -i off 打开: sudo mdutil -a -i on

  3. Python基础之给函数增加元信息

    1. 参数注解 当写好一个函数以后,想为这个函数的参数添加一些额外的信息,这样的话,其他的使用者就可以清楚的知道这个函数应该怎么使用,这个时候可以使用函数参数注解. 函数参数注解能提示程序员应该怎样正 ...

  4. python3实例

    1.一行代码求一个数的阶乘 例如:求5的阶乘 from functools import reduce print((lambda k: reduce(, k+), ))()) 借鉴:https:// ...

  5. shell 脚本同时对远程多台机器执行命令

    脚本1:需要机器之间免密 ssh-copy-id [-i [identity_file]] [user@]machine #!/bin/bash # ------------------------- ...

  6. OpenFOAM中的基本变量快速认知【转载】

    转载自:http://blog.sina.com.cn/s/blog_a0b4201d0102vsf9.html label 实际上就是整型数据的变体,int,OF对它进行了包装,以适应32或64位系 ...

  7. PullToRefresh原理解析,pulltorefresh解析

    PullToRefresh原理解析,pulltorefresh解析 代码届有一句非常经典的话:"不要重复制造轮子",多少人看过之后便以此为本,把鲁迅的"拿来主义" ...

  8. Qt的插件开发

    写代码都是从不会到会,那么写博客也是同样的道理.从不会到会最实用的办法就是模仿了.关于Qt的知识很多都是学习了CSDN的一位大神 一去二三里.关于Qt插件的开发,我们也从他的文章里面抽丝剥茧,把最本质 ...

  9. python3.6+pycharm+robotframework 环境搭建

    参考文档:https://www.cnblogs.com/chenyuebai/p/8359577.html, https://www.cnblogs.com/jiyanjiao-702521/p/9 ...

  10. java JSON的使用和解析

    There is no royal road to learning. 博主:JavaPanda https://www.cnblogs.com/LearnAndGet/p/10009646.html ...