Topic Link:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=1141
Test instructions: Determines whether the F (i) of the interval [a, b] is a prime number, F (i) =i*i+i+40;
Idea: Make a table, then pay attention to the accuracy;
#include <bits/stdc++.h>using namespacestd;#definell Long Long#defineESP 1E-13Const intn=1e4+Ten, m=1e6+50000, inf=1e9+Ten, mod=1000000007;intPrimeintN) { if(n<=1) return 0; if(n==2) return 1; if(n%2==0) return 0; intK, upperbound=n/2; for(k=3; k<=upperbound; k+=2) {Upperbound=n/K; if(n%k==0) return 0; } return 1;}intFintx) { returnx*x+ A+x;}intFlag[n];intMain () {intx,y,i,z,t; for(i=0; i<=10000; i++) if(Prime (f (i))) Flag[i+1]=flag[i]+1; ElseFlag[i+1]=Flag[i]; while(~SCANF ("%d%d",&x,&y)) {Doublesum=flag[y+1]-Flag[x]; DoubleDi= (y-x+1); Doubleans=sum/di*100.0+1e-8; printf ("%.2f\n", ans); } return 0;}
UVA 10200 Prime Time Water