UVA
来源:互联网 发布:qt matlab混合编程 编辑:程序博客网 时间:2024/06/03 22:05
题解:
精度精度!不懂为什么,难道是因为四舍五入的?
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.
Input
Each line of input will be given two positive integera andb such that 0≤ a≤ b≤ 10000. You mustread until the end of the file.
Output
For 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 390 4039 40
Sample Output
100.0097.5650.00
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<cmath>#include<sstream>#define inf 0x3f3f3fusing namespace std;#define maxn 10005double eps = 1e-6;typedef long long ll;int a[maxn];int is_prime(int n){ for(int i=2;i<=sqrt(n);i++) { if(n%i==0) return 0; } return 1;}void get(){ for(int i=0;i<maxn;i++) { int ans=i*i+i+41; a[i]=a[i-1]+is_prime(ans); }}int main(){ int a1,b1; get(); while(~scanf("%d%d",&a1,&b1)) { int d=a[b1]-a[a1-1]; printf("%.2lf\n",d*100.0/(b1-a1+1)+eps); } return 0;}
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- UVA
- java.lang.ClassNotFoundException: Didn't find class on path: DexPathList,nativeLibraryDirectories
- 阿里程序猿用这些黑科技欢迎年会
- 百度云的高速下载技巧系列3---批量文件下载工具pandownload v1.3.5版 (PC)
- Windows IO模型-WSAEventSelect模型(异步阻塞模型)
- lesson1:Windows程序运行原理及程序编写流程(vc++深入详解)
- UVA
- PHP实现执行定时任务的几种思路详解
- 大数据的四则运算
- pyCharm最新2017激活码
- 树莓派(二)——远程控制
- mysql bin-log日志基本操作与数据库备份还原
- SprintNBA模仿笔记(三)-3 导航栏标签和viewpager同步滚动
- Android之VideoView 进行播放视频 (不更新)
- 史上最大年会前夕,探班阿里总部