Poj 3292 semi-prime H-Numbers

Source: Internet
Author: User
Semi-prime H-Numbers Time Limit: 1000 msmemory limit: 65536 K Total submissions: 7372 accepted: 3158 Description

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


An H-number is a positive number which is one more than a multiple of four: 1, 5, 9, 13, 17, 21 ,... are the H-numbers. for this problem we pretend that these are the only numbers. the H-numbers are closed under multiplication.


As with regular integers, We partition the H-numbers into units, H-primes, and H-composites. 1 is the only unit. an H-Number H is H-prime if it is not the unit, and is the product of two H-numbers in only one way: 1 × H. the rest of the numbers are h-composite.


For examples, the first few H-composites are: 5 × 5 = 25, 5 × 9 = 45, 5 × 13 = 65, 9 × 9 = 81, 5 × 17 = 85.


Your task is to count the number of H-semi-primes. an H-semi-Prime is an H-number which is the product of exactly two H-primes. the two H-Primes may be equal or different. in the example above, all five numbers are h-semi-primes. 125 = 5 × 5 × 5 is not an H-semi-Prime, because it's the product of three H-primes.


Input


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


Output


For each inputted H-Number H, print a line stating h and the number of H-semi-primes between 1 and H random Sive, separated by one space in the format shown in the sample.


Sample Input


21
85
789

0


Sample output


21 0
85 5

789 62


Question: it is hard to understand the meaning of the question !! It is to find the number from 1 to the input. It can only be split into two numbers that multiply by 4n + 1 !!

However, this question is very meaningful. It makes me deeply understand the power of table playing. This is another problem that I encountered after Queen n !!



The AC code is as follows:

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#define M 1000001using namespace std;int aa[M+1];int bb[M+1];int main(){    int i,j;    int n;    int t=0,tj=0;    memset(aa,0,sizeof aa);    for(i=5;i<=M;i+=4)        for(j=5;j<=M;j+=4)        {            if(i*j>M)                break;            if(aa[i]==0&&aa[j]==0)                aa[i*j]=1;            else aa[i*j]=-1;        }    int ans=0;    for(i=1;i<=M;i++)    {        if(aa[i]==1)        {            ans++;        }        bb[i]=ans;    }    while(~scanf("%d",&n)&&n)    {        printf("%d %d\n",n,bb[n]);    }    return 0;}



Poj 3292 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.