UVA 10200
来源:互联网 发布:javascript用什么打开 编辑:程序博客网 时间:2024/06/06 23:53
Problem Description
Euler is a well-known matematician, and, among many other things, he discovered that the formulan2 + n+41 produces a prime for 0 ≤ n < 40. For n = 40, the formula produces 1681, which is 41 ∗ 41.Even though this formula doesn’t always produce a prime, it still produces a lot of primes. It’s knownthat for n ≤ 10000000, there are 47,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 certaininterval.InputEach line of input will be given two positive integer a and b such that 0 ≤ a ≤ b ≤ 10000. You mustread until the end of the file.OutputFor each pair a, b read, you must output the percentage of prime numbers produced by the formula inthis interval (a ≤ n ≤ b) rounded to two decimal digits.
Sample Input
0 39
0 40
39 40
Sample Output
100.00
97.565
0.00
题解:注意高精度,最后加个1e-8就行了。(不知道为啥->_->)
<span style="font-family:SimSun;">#include<cstdio>int s[10010];int prime(int n){for(int i=2;i*i<=n;i++)if(n%i==0)return 1;return 0;}int main(){for(int i=0;i<=10000;i++)s[i]=prime(i*i+i+41);double a,b,sum;while(~scanf("%lf%lf",&a,&b)){sum=0;for(int i=a;i<=b;i++){if(!s[i])sum+=1;}double v;v=sum/(b-a+1)*100;printf("%.2lf\n",v+1e-8);//高精度,不加不对。 }return 0;}</span>
- 【UVA 10200】
- uva 10200
- UVA-10200
- UVA 10200
- UVA 10200 Prime Time
- UVA 10200 Prime Time
- UVA 10200 (高精度)
- UVA-10200(素数)
- UVA 10200 Prime Time
- UVA-----10200 Prime Time
- UVA 10200 Prime Time
- UVA 10200 Prime Tim
- uva 10200 Prime Time
- UVA 10200 Prime Time
- uva
- UVA
- UVA
- UVA
- iOS_画一像素的线
- iOS原生态删除、置顶某行cell
- 一些面试题收集
- centos下为laravel框架配置nginx服务器虚拟主机
- 10. Regular Expression Matching(很重要!!!)
- UVA 10200
- 超实用压力测试工具-ab工具
- STM32中控制I/O口的寄存器们
- 代码的自动生成与编译(一)
- Apache ActiveMQ启动DEMO错误
- 【C语言】文件指针与文件位置指针,位置指针相关操作库函数
- java海量数据导出xls分页解决报内存溢出问题
- 如何在SQL Server实现类似RowNum伪列
- iOS支付宝集成详细流程