Title Address: POJ 3292
First use the principle of prime sieve to sift out the h_prime, and then hit the table. To be preprocessed, otherwise tle.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL __int64#define Pi ACOs ( -1.0) const int Mod=100000000;const int Inf=0x3f3f3f3f;const double eqs=1e -8;int h_prime[1000000], tot, check[1000100], vis[1000002], num[1000002];void init () {int i, J; LL x, ans=0; tot=0; memset (check,0,sizeof (check)); for (i=5;i<=1000001;i+=4) {if (!check[i]) {h_prime[tot++]=i; } for (j=0;j<tot;j++) {if (i*h_prime[j]>1000001) break; Check[i*h_prime[j]]=1; if (i%h_prime[j]==0) break; }} for (i=0;i<tot;i++) {for (j=0;j<tot;j++) {X=h_prime[i]*h_prime [j]; if (x> 1000001) break; if (!vis[x]) {vis[x]=1; }}} for (i=0;i<1000001;i++) {if (vis[i]) ans++; Num[i]=ans; }}int Main () {int n, I, POS, J; LL ans, X; Init (); while (scanf ("%d", &n)!=eof&&n) {printf ("%d%d\n", n,num[n]); } return 0;}
POJ 3292 semi-prime h-numbers (imitation Prime sieve)