Test instructions
You are now in a world where all the numbers are modulo 4 to 1, that is, there is no other number except for this number.
However, the definition of prime is still unchanged, if a number cannot be written as the product of two non-1 numbers, it is a prime.
For example, here 5 becomes the smallest prime number.
Two primes multiply to get a half prime, such as 5x5 = 25, which is the smallest half prime.
Find out how many half primes are 1~h between the two.
Analysis:
Although it is required to [1, h] between the number of semi-prime, but to the usual sieve ordinary prime numbers of all 4k+1 first sieve out.
Then the two-cycle enumeration of the half primes, the last statistical interval [1, h] of the semi-prime number of SUMH
1#include <cstdio>2#include <cstring>3#include <cmath>4 using namespacestd;5 6 Const intMAXN =1000000+1;7 BOOLVIS[MAXN +Ten];8 intprime[100000], CNT, SUM[MAXN +Ten];9 Ten voidInit () One { A intm = sqrt (MAXN +0.5); - for(inti =5; I <= m; i + =4)if(!Vis[i]) - for(intj = i * I; J <= Maxn; J + =i) theVIS[J] =true;//h-Prime selection - - for(inti =5; I <= MAXN; i + =4)if(!vis[i]) prime[cnt++] =i; - +memset (Vis,false,sizeof(Vis)); - for(inti =0; I < CNT; i++) +{//Filter H-Primes A for(intj = i; J < CNT; J + +) at { - Long LongK = (Long Long) Prime[i] * (Long Long) prime[j]; - if(K > (Long Long) MAXN) Break; -VIS[K] =true; - } - } in - for(inti = -; I <= MAXN; i++) Sum[i] = sum[i-1] +Vis[i]; to } + - intMain () the { *Freopen ("In.txt","R", stdin); $ Init ();Panax Notoginseng intN; - while(SCANF ("%d", &n) = =1&& N) printf ("%d%d\n", N, Sum[n]); the + return 0; A}
code June
UVa 11105 (Sieve method) Semi-prime H-numbers