Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

数据都通过,是哪错了?哪位大虾帮忙看看,感激不尽

Posted by qiufeng6407 at 2011-04-26 20:15:16 on Problem 2739
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int n,i,j,k;
    while(scanf("%d",&n) != EOF) {
       if(n == 0) {
          break;     
       }
       int a[10000],x = 0;
       bool b[10000];
       //初始化 
       for(i = 2; i <= n; i++) {
          b[i] = true;
       }
       //去除偶数 
       for(i = 3; i <= n; i++) {
          if( i % 2 == 0) {
              b[i] = false;
          }
       }
       //去除 倍数
       for(i = 3; i <= sqrt(n * 1.0); i += 2) {
          if(b[i]) {
              for(j = i + i; j < n; j += i) {
                    b[j] = false;
              }
          } 
       }
       //赋值 
       for(i = 2,j = 0; i <= n; i++) {
          if(b[i]) {
              a[j] = i;
              j++;
          } 
       }
       //遍历 
       for(i = 0; i <= j; i++) {
          int sum = a[i];
          for(k = i + 1; k <= j; k++) {
             if(sum == n) {
                x++;
                break;
             }
             if(sum > n) {
                break;
             }
             sum += a[k];
          }
       }
       //输出 
       printf("%d\n",x);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator