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 ...
随机推荐
- CF757F Team Rocket Rises Again——最短路+支配树
CF757F Team Rocket Rises Again 全体起立,全体起立,这是我A的第一道黑题(虽然是CF的): 来一波番茄攻击: 不扯淡了,这道题也是学习支配树(之前)应该做的题: 和灾难不 ...
- vue-cli构建路径加载资源出错问题
这份文档是对应 @vue/cli 3.x 版本的,官方文档https://cli.vuejs.org/zh/guide/ 项目打包执行npm run build的时候,打开dist目录的index.h ...
- 走进JavaWeb技术世界14:通过项目逐步深入了解Mybatis(一)
通过项目逐步深入了解Mybatis(一) 2017-06-12 文章导航 Mybatis 和 SpringMVC 通过订单商品案例驱动 官方中文地址:http://www.mybatis.org/my ...
- IOS添加真机调试设备
注意点: 有时需要同意协议什么的,很多时候刷新出来都是白屏,解决办法: 对于不能确认新协议的问题,我发现了一个解决方法:登陆后,直接在浏览器的地址框访问:https://developer.apple ...
- 20165223《网络对抗技术》Exp7 网络欺诈防范
目录 -- 网络欺诈防范 实践说明 实践目标 基础知识问答 实验工具学习 实践内容 简单应用SET工具建立冒名网站 ettercap DNS spoof 结合应用两种技术,用DNS spoof引导特定 ...
- 2018-2019-2 20165114《网络对抗技术》 Exp 8 Web基础
Exp 8 Web基础 目录 一.实验内容 二.基础问题回答 (1)什么是表单 (2)浏览器可以解析运行什么语言. (3)WebServer支持哪些动态语言 三.实践过程记录 3.1Web前端HTML ...
- 【Java】浅谈Java内部类(转载)
说得挺细的,不是泛泛而谈.https://blog.csdn.net/weixin_42762133/article/details/82890555
- python 设计模式之享元(Flyweight)模式
#写在前面 这个设计模式理解起来很容易.百度百科上说的有点绕口. #享元模式的定义 运用共享技术来有効地支持大量细粒度对象的复用. 它通过共享已经存在的对橡大幅度减少需要创建的对象数量.避免大量相似类 ...
- OSError: image file is truncated (28 bytes not processed)
解决办法: 在代码中添加两行 from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True
- Qt自定义类重写 copy
PtsData PtsData::copy(const PtsData &ptsData) { PtsData ptsData1; ptsData1.data_b = ptsData.data ...