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

怎么Runtime Error了??请教

Posted by guanqun at 2007-06-16 17:02:27 on Problem 3090
#include <iostream>
using namespace std;

int mygcd(int x, int y)
{
	while(y>0){
		int temp = x%y;
		x = y;
		y = temp;
	}

	return x;
}

int main()
{
	// preprocessor
	
	int a[1001][1001] = {0};
	int s[1001] = {0};

	a[1][0] = 1;
	a[0][1] = 1;
	a[1][1] = 1;

	for(int y=1; y<1001; y++){
		for(int x=y+1; x<1001; x++){
			if(mygcd(x, y) == 1){
				a[x][y] = 1;
				a[y][x] = 1;
			}
		}
	}

	s[0] = 0;
	s[1] = 3;

	for(int i=2; i<1001; i++){
		s[i] += s[i-1];
		for(int j=1; j<=i; j++){
			s[i] += 2*a[i][j];
		}
	}

	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int input;
		cin >> input;

		cout << i+1 << ' ' << input << ' ' << s[input] << endl;

	}

	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