HEU 2038 Assistance Required

/**************************************
Problem: HEU 2038 Assistance Required
Time: 0.2460 s
Memory: 576 k 
Accepted Time: 2009-05-08 20:36:28
Tips: 打表 
*************************************
*/

#include 
<stdio.h>
#include 
<string.h>
#define MAX 35000
int main()
{
    
bool table[MAX+9];
    
int num[3005];
    memset(table,
1,sizeof(table));
    
int i,j,k=1,count;
    
for(i=2;i<=MAX;i++)
    
{
        
if(table[i])
        
{
            num[k
++]=i;
            
if(k>3002)
            
{
                
break;
            }

            count
=0;
            
for(j=i+1;j<=MAX;j++)
            
{        
                
if(table[j])count++;
                
if(count==i)
                
{
                    table[j]
=0;
                    count
=0;
                }

                
            }

        }

    }

    
int n;
    
while(scanf("%d",&n),n!=0)
    
{
        printf(
"%d\n",num[n]);
    }

    
return 0;
}

posted @ 2009-05-08 20:43  主函数  阅读(176)  评论(0编辑  收藏  举报