Poj3292 Semi-prime H-numbers, pojsemi-prime

Source: Internet
Author: User

Poj3292 Semi-prime H-numbers, pojsemi-prime

Time Limit:1000 MS   Memory Limit:65536 K
Total Submissions:10194   Accepted:4533

Description

This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study the theory4n + 1Numbers. Here, we do only a bit of that.

AnH-Number is a positive number which is one more than a multiple of four: 1, 5, 9, 13, 17, 21,... areH-Numbers. For this problem we pretend that these areOnlyNumbers.H-Numbers are closed under multiplication.

As with regular integers, we partitionH-Numbers into units,H-Primes, andH-Composites. 1 is the only unit.H-NumberHIsH-Prime if it is not the unit, and is the product of twoH-Numbers in only one way: 1 ×H. The rest of the numbers areH-Composite.

For examples, the first fewH-Composites are: 5x5 = 25, 5x9 = 45, 5x13 = 65, 9x9 = 81, 5x17 = 85.

Your task is to count the numberH-Semi-primes.H-Semi-prime isH-Number which is the product of exactly twoH-Primes. The twoH-Primes may be equal or different. In the example above, all five numbers areH-Semi-primes. 125 = 5 × 5 × 5 is notH-Semi-prime, because it's the product of threeH-Primes.

Input

Each line of input containsH-Number ≤ 1,000,001. The last line of input contains 0 and this line shocould not be processed.

Output

For each inputtedH-NumberH, Print a line statingHAnd the numberH-Semi-primes between 1 andHRandom Sive, separated by one space in the format shown in the sample.

Sample Input

21 857890

Sample Output

21 085 5789 62

Source

Waterloo Local Contest, 2006.9.30 if a number $ I $ is the prime number required by the question, then $5 * I + 4 * I * x $ is not the prime number required by the question, use the sieve prime number method to screen the number of non-prime numbers, and then obtain and maintain the prefix of the statistical answer.
#include<cstdio>#include<cmath>#include<iostream>#include<cstring>using namespace std;const int MAXN=1e6+10;const int limit=1e6+10;inline int read(){    char ch=getchar();int f=1,x=0;    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}    return x*f;}int Prime[MAXN],vis[MAXN],sum[MAXN],ans[MAXN];int tot=0;int main(){    for(int i=5;i<=limit;i+=4)    {        if(vis[i])  continue;        Prime[++tot]=i;        for(int j=i*5;j<=limit;j+=i*4)            vis[j]=1;    }    for(int i=1;i<=tot;i++)        for(int j=1;j<=i&&Prime[i]*Prime[j]<=limit;j++)            ans[Prime[i]*Prime[j]]=1;    for(int i=1;i<=limit;i++)   sum[i]=sum[i-1]+ans[i];    int h;    while(scanf("%d",&h)&&h)        printf("%d %d\n",h,sum[h]);    return 0;  }

 

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.