解题思路:
1 首先判断prime:H-numbers, 下标i表示4*i+1,j表示4*j+1,则(4*i+1)*(4*j+1)=4(4*i*j+i+j)+1,即下表i,j的乘积为下标4*i*j+i+j,判断prime方法类似判断普通prime方法,Line 10~12
2 判断Semi-prime,prime以及prime与no-prime的乘积肯定为非Semi-prime,Line 15~22
3 统计
代码
1
#include
<
iostream
>
2 using namespace std;
3 #define MAXN 250001
4 bool IsPri[MAXN],IsSPri[MAXN];
5 int col[MAXN],pri[ 200 ];
6 int main()
7 {
8 int n,i,j,t,p,ans;
9 memset(IsPri, 0x01 , sizeof (IsPri));
10 for (IsPri[ 0 ] = p = 0 ,i = 1 ;i < 251 ;i ++ )
11 if (IsPri[i])
12 for (pri[p ++ ] = i,j = i;( 4 * i * j + i + j) < MAXN;j ++ )
13 IsPri[ 4 * i * j + i + j] = false ;
14 memset(col, 0 , sizeof (col));
15 for (i = 0 ;i < MAXN;i ++ )IsSPri[i] = IsPri[i] ? 0 : 1 ;
16 for (IsSPri[ 0 ] = i = 0 ;i < p;i ++ )
17 for (t = 0 ,j = pri[i] + 1 ;t < MAXN;j ++ )
18 {
19 if (IsPri[j]) continue ;
20 t = j * pri[i] * 4 + j + pri[i];
21 if (t < MAXN)IsSPri[t] = 0 ;
22 }
23 for (i = 1 ;i < MAXN;i ++ )
24 if (IsSPri[i])col[i] = col[i - 1 ] + 1 ;
25 else col[i] = col[i - 1 ];
26 while (scanf( " %d " , & n) && n)
27 printf( " %d %d\n " ,n, col[(n - 1 ) / 4 ]);
28 return 0 ;
29 }
2 using namespace std;
3 #define MAXN 250001
4 bool IsPri[MAXN],IsSPri[MAXN];
5 int col[MAXN],pri[ 200 ];
6 int main()
7 {
8 int n,i,j,t,p,ans;
9 memset(IsPri, 0x01 , sizeof (IsPri));
10 for (IsPri[ 0 ] = p = 0 ,i = 1 ;i < 251 ;i ++ )
11 if (IsPri[i])
12 for (pri[p ++ ] = i,j = i;( 4 * i * j + i + j) < MAXN;j ++ )
13 IsPri[ 4 * i * j + i + j] = false ;
14 memset(col, 0 , sizeof (col));
15 for (i = 0 ;i < MAXN;i ++ )IsSPri[i] = IsPri[i] ? 0 : 1 ;
16 for (IsSPri[ 0 ] = i = 0 ;i < p;i ++ )
17 for (t = 0 ,j = pri[i] + 1 ;t < MAXN;j ++ )
18 {
19 if (IsPri[j]) continue ;
20 t = j * pri[i] * 4 + j + pri[i];
21 if (t < MAXN)IsSPri[t] = 0 ;
22 }
23 for (i = 1 ;i < MAXN;i ++ )
24 if (IsSPri[i])col[i] = col[i - 1 ] + 1 ;
25 else col[i] = col[i - 1 ];
26 while (scanf( " %d " , & n) && n)
27 printf( " %d %d\n " ,n, col[(n - 1 ) / 4 ]);
28 return 0 ;
29 }