UVA 10200 Prime Time【暴力,精度】
题目链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1141
题意:
给定区间,求区间内所有整数a,f(a) = a * a + a - 1为质数的概率。
分析:
卡精度卡的蛋疼。。
最后要加个eps处理四舍五入问题。。不是很懂。。
代码:
#include<cstdio>
const int maxm = 1e4 + 5;
double eps = 1e-6;
int cnt[maxm];
bool prime(int a)
{
for(int i = 2; i * i <= a; i++){
if(a % i == 0) return false;
}
return true;
}
void getans()
{
for(int i = 0; i < maxm; i++){
int ans = i * i + i + 41;
cnt[i] = cnt[i - 1] + prime(ans);
}
}
int main (void)
{
int a, b;
getans();
while(~scanf("%d%d", &a, &b)){
int ans = cnt[b] - cnt[a - 1];
printf("%.2f\n", ans * 100.0 / (b - a + 1) + eps);
}
return 0;
}
UVA 10200 Prime Time【暴力,精度】的更多相关文章
- UVA - 10200 Prime Time 关于 double类型 卡精度
题意: 给定一个区间,a到b, n在区间内,有一个计算素数的公式,n*n+n+41,将n带进去可以得出一个数字.但是这个公式可能不准确,求出这个公式在这个区间内的准确率. 直接模拟就好了,不过要 注意 ...
- UVA 10200 Prime Time 水
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA 10200 Prime Time (打表)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)
两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...
- UVA - 524 Prime Ring Problem(dfs回溯法)
UVA - 524 Prime Ring Problem Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & % ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- UVA.10305 Maximum Product (暴力)
UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...
- Prime Time UVA - 10200(精度处理,素数判定)
Problem Description Euler is a well-known matematician, and, among many other things, he discovered ...
- 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板
题意:验证1~10000 的数 n^n+n+41 中素数的个数.每个询问给出a,b 求区间[a,b]中质数出现的比例,保留两位 题解:质数会爆到1e8 所以用miller robin , 另外一个优 ...
随机推荐
- android studio 生成 jniLibs 目录
现在一般的项目都会加入第三方jar包,第三方jar包我们会新建一个文件夹:libs,然后jar包都放在这个文件夹中. 但我们会发现,只是新建一个文件加之后,在AndroidStudio的左侧并不会出现 ...
- /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
[root@localhost nagios]# make install-webconf/usr/bin/install -c -m 644 sample-config/httpd.conf /et ...
- JDBC基础-setFetchSize方法
在Statement和ResultSet接口中都有setFetchSize方法 void setFetchSize(int rows) throws SQLException 查看API文档 Stat ...
- ES5函数新增的方法(call、apply、bind)
1.call()的使用<script type="text/javascript"> var obj1 = { name:'bob', fn:function(){ c ...
- (译)IOS block编程指南 2 block开始
Getting Started with Blocks(开始block) The following sections help you to get started with blocks usin ...
- laravel扩展包服务提供者的注册的两种方式
一. 包自动发现 在 Laravel 应用的配置文件 config/app.php 中,providers 配置项定义了一个会被 Laravel 加载的服务提供者列表.当安装完新的扩展包后,在老版本中 ...
- 聊天室(C++客户端+Pyhton服务器)2.基本功能添加
根据之前的框架添加新的功能 登录 点击相关按钮 // 登录按钮的响应void CMainDialog::OnBnClickedLogin(){ // 1. 获取用户输入的数据 UpdateData(T ...
- 【软件构造】第三章第四节 面向对象编程OOP
第三章第四节 面向对象编程OOP 本节讲学习ADT的具体实现技术:OOP Outline OOP的基本概念 对象 类 接口 抽象类 OOP的不同特征 封装 继承与重写(override) 多态与重载( ...
- No-4.文件和目录常用命令
文件和目录常用命令 结构 查看目录内容 ls 切换目录 cd 创建和删除操作 touch rm mkdir 拷贝和移动文件 cp mv 查看文件内容 cat more grep 其他 echo 重定向 ...
- 448. Find All Numbers Disappeared in an Array@python
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...