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 ...
随机推荐
- 持续api管理翻译
- 书籍内容 > 地址: https://www.safaribooksonline.com/library/view/continuous-api-management/97814920435 ...
- yarn-site.xml 基本配置参考
以下只是对yarn配置文件(yarn.site.xml)简单的一个配置 <configuration> <!-- rm失联后重新链接的时间 --> <property&g ...
- js对元素判断
$("input[type='text']").attr("readonly","readonly"); $("textarea& ...
- Leetcode第三题《Longest Substring Without Repeating Characters》
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- Echarts常用API(echarts和echartsInstance)
一.echarts上的方法 一般在项目中引入echarts之后,可以获得一个全局的echarts对象. 1.下面是几个比较常用的echarts方法 echarts.init() 创建一个echarts ...
- Navicat Premium 12安装与激活(亲测已成功激活)
说明:博主所提供的激活文件理论支持Navicat Premium 12.0.16 - 12.0.24简体中文64位,但已测试的版本为Navicat Premium 12.0.22.12.0.23和12 ...
- office web apps 在线问答预览
最近在做项目时,需要用到在线文档预览,看过明道的一篇搭建office web apps服务的文章,但是由于时间的关系,没有仔细研究,这几天有时间,就拿出来研究了下,折腾了几天终于完成了部署,然后就搬过 ...
- LightGBM与评分卡
调参策略 最大化 off_ks + 0.8(off_ks-train_ks) import pandas as pd from sklearn.metrics import roc_auc_score ...
- celery的介绍和在爬虫的中使用
https://mp.weixin.qq.com/s/FzvZHQpF5mhV9t_HBzlcwg
- 简易的CRM系统案例之Servlet+Jsp+MySQL版本
数据库配置 datebase.properties driver=com.mysql.jdbc.Driver url=jdbc:mysql://127.0.0.1:3306/infos usernam ...