POJ 3292 Semi-prime H-numbers (Quantity)
Semi-prime H-numbers
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
Meaning all can be expressed as 4 * k + 1 (k> = 0) the number is called the "H Number". In all the "H Number", the number of H which can only be divided by 1 and itself is called the product of "H prime number" which can be expressed as two "H prime number ". number, also known as "Semi-prime H Number"
Enter n to calculate the number of "Semi-prime H" between 1 and n.
The method is to create an H prime number table and then multiply the numbers in the H prime number table to mark the numbers. Then, use an array to save the numbers within each number. Input n and then read the array directly.
#include
#include
#include
#includeusing namespace std;const int N=1000001;int vis[N],hp[N],ans[N],n;int main(){ int num=0,m=sqrt(N+0.5); for(int i=5;i<=m;i+=4) { if(vis[i]==0) for(int j=i*i;j<=N;j+=i) vis[j]=1; } for(int i=5;i
=1) ++num; ans[i]=num; } while(scanf("%d",&n),n) printf("%d %d\n",n,ans[n]); return 0;}