UVa 11105 (Sieve method) Semi-prime H-numbers

Source: Internet
Author: User

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

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.