POJ 3292 semi-prime h-numbers (imitation Prime sieve)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.