H-number是指形如4n+1(n>=0)的整数,后又定义了好几种数。
水题。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define N 1000002
bool NotaHprime[N],IsaHsemiprime[N];
int ans[N];
int main()
{
int i,j;
memset(NotaHprime,false,sizeof(NotaHprime));
memset(IsaHsemiprime,false,sizeof(IsaHsemiprime));
for (i=5; i<1002; i+=4)
{
for (j=i; i*j<N; j+=4)
{
NotaHprime[i*j]=true;
}
}
for (i=5; i<1002; i+=4)
{
for (j=i; i*j<N; j+=4)
{
if (!NotaHprime[i] && !NotaHprime[j])
IsaHsemiprime[i*j]=true;
}
}
ans[1]=0;
for (i=2; i<N; i++)
{
if (IsaHsemiprime[i])
ans[i]=ans[i-1]+1;
else
ans[i]=ans[i-1];
}
while (1)
{
scanf("%d",&i);
if (i == 0)
break;
printf("%d %d\n",i,ans[i]);
}
}