- 因为向下取整的运算,所以在做精度的题时一定要加1e+8。
- 打表可以控制在10^8。
题目链接:http://acm.hust.edu.cn/vjudge/problem/22214
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<string>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<vector>
#include<fstream>
#include<list>
using namespace std;
#define ms(s) memset(s,0,sizeof(s))
typedef unsigned long long ULL;
typedef long long LL;
const int INF = 0x3fffffff;
const int N = 100010041;
bool primeTable[N+5];
void make_primeTable(){
fill(primeTable,primeTable+N,1);
primeTable[0] = false;
primeTable[1] = false;
int maxed = sqrt(N);
for(int i = 2; i <= maxed; ++i){
if(primeTable[i]){
for(int j = i*i; j <= N; j += i)
primeTable[j] = false;
}
}
}
int main(){
// freopen("F:\\input.txt","r",stdin);
// freopen("F:\\output.txt","w",stdout);
// ios::sync_with_stdio(false);
make_primeTable();
int ans;
int a,b;
int num;
double pa,pb;
while(~scanf("%d%d",&a,&b)){
num = 0;
for(int i = a; i <= b; ++i){
ans = i*i+i+41;
if(primeTable[ans] == true)
++num;
}
pa = (double)num*100.0;
pb = (double)(b-a)+1.0;
printf("%.2f\n",pa/pb+1e-8);
}
return 0;
}