题目链接:

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【暴力,精度】的更多相关文章

  1. UVA - 10200 Prime Time 关于 double类型 卡精度

    题意: 给定一个区间,a到b, n在区间内,有一个计算素数的公式,n*n+n+41,将n带进去可以得出一个数字.但是这个公式可能不准确,求出这个公式在这个区间内的准确率. 直接模拟就好了,不过要 注意 ...

  2. UVA 10200 Prime Time 水

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. UVA 10200 Prime Time (打表)

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. UVA - 11827 - Maximum GCD,10200 - Prime Time (数学)

    两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> ...

  5. UVA - 524 Prime Ring Problem(dfs回溯法)

    UVA - 524 Prime Ring Problem Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & % ...

  6. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  7. UVA.10305 Maximum Product (暴力)

    UVA.10305 Maximum Product (暴力) 题意分析 直接枚举起点和重点,然后算出来存到数组里面,sort然后取最大值即可. 代码总览 #include <iostream&g ...

  8. Prime Time UVA - 10200(精度处理,素数判定)

    Problem Description Euler is a well-known matematician, and, among many other things, he discovered ...

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

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

随机推荐

  1. java实现斐波那契的两种方法

    package com.ywx.count; /** * 斐波那契数列(地推方式要比递归方式的效率要高) * @author Vashon(yangwenxue) * date:20150320 */ ...

  2. Redis学习笔记(三)列表进阶

    RPOPLPUSH source destination(弹出source列表最右端的元素,并推入destination的最左端,同时返回这个元素) BRPOPLPUSH source destina ...

  3. makefile vpath变量

    在讲vpath之前,我们首先了解以下makefile文件. 在类Unix系统中,当我们使用源码编译某个软件的时候,我们会使用confiure,make,make install这三个命令,其中cofi ...

  4. Python3基础教程(二十)—— flask介绍

    基本概念 什么是Flask? Flask 是一个 web 框架.也就是说 Flask 为你提供工具,库和技术来允许你构建一个 web 应用程序.这个 web 应用程序可以是一些 web 页面.博客.w ...

  5. Animate.css_css3动画库介绍

    插件描述:Animate.css内置了很多典型的css3动画,兼容性好使用方便. Animate.css是一个有趣的,跨浏览器的css3动画库.很值得我们在项目中引用. 用法 1.首先引入animat ...

  6. upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量

    upload 上传 加token 在 :headers='headers' 注意 不要直接写$refs.upload.headers = {} 这样vue会警告 修改组件内部变量 <Upload ...

  7. 基于纯注解的spring开发的介绍

    几个核心注解的介绍1.@Configuration它的作用是:将一个java类修饰为==配置文件==,在这个java类进行组件注册1package com.kkb.config; import org ...

  8. Java 对象的创建以及类加载

    1. 对象的创建的过程: 类加载检查—>分配内存—>初始化零值—>设置对象头—>执行 init . 1.类加载检查: 虚拟机遇到一条 new 指令时,首先将去检查这个指令的参数 ...

  9. Django 1.8.11 REST风格路由

    # -*- coding: utf-8 -*- """ Tencent is pleased to support the open source community b ...

  10. LeetCode(12)Integer to Roman

    题目 Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from ...