poj 3292 Semi-prime H-numbers

数论水题,利用筛选法……

 1 #include<iostream>

 2 #include<stdio.h>

 3 #include<algorithm>

 4 #include<vector>

 5 #include<cmath>

 6 #include<iomanip>

 7 #include<string>

 8 using namespace std;

 9 int an[1000001];

10 int main()

11 {

12     int i,j,k,n;

13     memset(an,0,sizeof(an));

14     for(i=5;i<=1000000;i+=4)

15     {

16         for(j=5;j<=1000000;j+=4)

17         {

18             if(i*j>1000000)

19                 break;

20             if(an[j]==0&&an[i]==0)

21                 an[i*j]=1;

22             else an[i*j]=-1;

23         }

24     }

25     k=0;

26     an[1]=0;

27     for(i=5;i<=1000000;i+=4)

28         if(an[i]==1)

29         {

30             an[i]=++k;

31         }

32         else an[i]=k;

33     while(cin>>n&&n)

34     {

35         cout<<n<<' '<<an[n]<<endl;

36     }

37     return 0;

38 }
View Code

 

你可能感兴趣的:(number)