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

同样的代码,C++就accept, g++就runtime error

Posted by lidaobing at 2006-12-29 20:17:00 on Problem 2262
谁能帮忙解释一下么?

#include <iostream>

using namespace std;

int main() {
  int prime[1000000];
  int i;
  for(i = 0; i < 1000000; ++i) {
    prime[i] = 1;
  }
  for(i = 3; i < 1000; i += 2) {
    if(!prime[i]) continue;
    for(int j = i; j <= 1000000/i; j += 2) {
      prime[i*j] = 0;
    }
  }

  while(1) {
    int n;
    cin >> n;
    if(n == 0) break;
    for(i = 3; i < 1000000; i+=2) {
      if(prime[i] && prime[n-i]) {
        cout << n << " = " << i << " + " << n - i << '\n';
        break;
      }
    }
  }
}

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