Prime Time UVA - 10200(精度处理,素数判定)
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 < 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(精度处理,素数判定)的更多相关文章
- 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板
题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b 求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优 ...
- FZU 1649 Prime number or not米勒拉宾大素数判定方法。
C - Prime number or not Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429
素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...
- 10^9以上素数判定,Miller_Rabin算法
#include<iostream> #include<cstdio> #include<ctime> #include<string.h> #incl ...
- HDU2138 素数判定
HDU2138 给定N个32位大于等于2的正整数 输出其中素数的个数 用Miller Rabin 素数判定法 效率很高 数学证明比较复杂,略过, 会使用这个接口即可. #include<iost ...
- codevs——1430 素数判定
1430 素数判定 时间限制: 1 s 空间限制: 1000 KB 题目等级 : 青铜 Bronze 题解 题目描述 Description 质数又称素数.指在一个大于1的自然数中, ...
- [算法]Miller-Robbin素数判定
目录 一.实现原理 二.应用 判断一个正整数是否为素数 三.小结 一.实现原理 我们以前都是怎么判断素数的呢: 试除法: 若一个正整数N为合数,则存在一个能整除N的数k,其中\(2\leqslant ...
- HDOJ2012素数判定
素数判定 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- algorithm@ 大素数判定和大整数质因数分解
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...
随机推荐
- ajax请求数据动态填充之文档与字符串区别手法
success: function(data){ if(data.status==200){ var realName=data.doc.realName; $("#yishiul" ...
- Tkinter 之Button标签
一.参数说明 语法 作用 Button(root,text='xxxx') 按钮图标显示内容 Button(root,text='xxxx',height=2) 组件的高度(所占行数) Button( ...
- 关于大JSON 的问题的解决方式
ASP.NET MVC JSON 大数据异常提示JSON 字符串超出限制的异常问题 今天客户突然过来找我说在后台添加了一篇超长的文章后,所有后台的文章都显示不出来了.后台的前端显示是用easyui的, ...
- Git 工作流
一.分类 1.集中式工作流 像 SVN 一样,集中式工作流以中央仓库作为项目所有修改的单点实体.所有修改都提交到 Master 这个分支上. 这种方式与 SVN 的主要区别就是开发人员有本地库.Git ...
- 编程微语 2019-Autumn
很多时候我们要的是[网页全屏],可是许多软件却做成了[浏览器全屏],不要一听到[全屏]就认为真的是传统意义上的全屏.拜托,老板(往往就是最大的产品经理).产品经理.程序员,想想,说清楚,做正确.某度文 ...
- linux下如何删除乱码文件
首先执行ls -i命令,此时在文件前面会出现一个数字,这个数字是文件的节点号 接着,执行命令 find -inum 节点号 -delete 即可将乱码文件成功删除
- RK3399 4G模块移远EC20移植调试
转载请注明出处:https://www.cnblogs.com/lialong1st/p/11266330.html CPU:RK3399 系统:Android 7.1 1.通过串口打印或者adb获取 ...
- mysql 触发器语法详解
1.创建Mysql触发器: 语法: CREATE TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW BE ...
- vue项目中 favicon.ico不能正确显示的问题
方法一:修改index.html文件 <link rel="shortcut icon" type="image/x-icon" href="f ...
- float和int转换
http://blog.sina.com.cn/s/blog_5c6f79380101bbrd.html https://blog.csdn.net/ganxingming/article/detai ...