POJ 2739 Sum of Consecutive Prime Numbers

/**************************************
Problem: POJ 2739 Sum of Consecutive Prime Numbers
Time: 16MS
Memory: 212K 
Accepted Time: 2009-05-16 12:46:01
Tips: 
*************************************
*/

#include 
< stdio.h >
#include 
< string .h >
#define  MAX 10000
int  main()
{
    
bool num[MAX+1];
    
int n,i,j;
    memset(num,
1,sizeof(num));
    
for(i=2;i<=MAX/2;i++)
    
{
        
if(num[i])
        
for(j=2;i*j<=MAX;j++)num[i*j]=0;
    }

    
while(scanf("%d",&n),n!=0)
    
{
        
int count=0;
        
for(i=n;i>1;i--)
        
{
            
if(num[i])
            
{
                
int sum=0;
                
for(j=i;sum<n&&j>1;j--)
                
{
                    
if(num[j])sum+=j;
                }

                
if(sum==n)count++;
            }

        }

        printf(
"%d\n",count);
    }

    
return 0;
}

你可能感兴趣的:(number)