E-Semi-prime H-numbers
Time limit:1000 MSMemory limit:65536KB64bit Io format:% I64d
& % I64u
SubmitStatus
Description
This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study the theory
4N + 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,... are
H-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 two
H-Numbers in only one way: 1 ×H. The rest of the numbers are
H-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 two
H-Primes. The twoH-Primes may be equal or different. In the example above, all five numbers are
H-Semi-primes. 125 = 5 × 5 × 5 is notH-Semi-Prime, because it's the product of three
H-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 stating
HAnd 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 the question is something like the number of 4n + 1 we call it the number of H-NUMBER and now we're looking for a rangeH-Semi-how many primes are there?H-Semi-Primes: This number is what it can and can only be obtained by multiplying the number of two H-PRIMES (by multiplying the number of groups of H-PRIMES to get no relation for example 441 = 21*21 = 9*49 but it also belongH-Semi-Primes category), and the number of H-PRIMES is the number can only be multiplied by the number of 1 and the number of H-NUMBER to pay attention to a condition given in the questionH-Numbers are closed under multiplication. this multiplication operation is closure, that is, (4 * n + 1) * (4 * m + 1) = 4 * k + 1 where n m K is a positive integer greater than or equal to 1. Therefore, to solve this problem, we only need to perform brute force screening on the numbers that meet the conditions, after filtering all the data, count the number of matching conditions. Very simple .. I have no knowledge of number theory in it, but I don't know if the number of this question will become larger. Will the brute force screening be pasted with my code under TLE...#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;#define MAXN 10000001int H[MAXN+1];void choose(){ int i,j; memset(H,0,sizeof(H)); for(i=5;i<=MAXN;i+=4) { for(j=5;j<=MAXN;j+=4) { if(i*j>MAXN)break; if(H[i]==0&&H[j]==0) H[i*j]=1; else H[i*j]=-1; } }int count=0;for(i=1;i<=MAXN;i++) { if(H[i]==1) count++; H[i]=count; }}int main(){ int h; choose(); while(scanf("%d",&h)!=EOF) { if(h==0) return 0; cout<