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 ljp at 2011-12-10 17:43:35 on Problem 3006
#include <iostream>
#include <vector>
using namespace std;

#define Max 1000000
int numArray[Max];
//vector<int> Prime;

void getPrimeNumber() {
	for (int i = 0; i < Max; i++) {
		numArray[i] = 1;
	}
	numArray[0] = 0, numArray[1] = 0;
	for (int i = 2; i < Max; i++) {
		if (numArray[i] == 1) {
			//Prime.push_back(i);
			for (int j = i * 2; j < Max; j += i)
				numArray[j] = 0;
		}
	}
}
int main() {
	int a, d, n, index, number;
	getPrimeNumber();
	while (cin >> a >> d >> n && a + d + n != 0) {
		index = 0;
		number = a;
		while (index != n) {
			if (numArray[number] == 1)
				index++;
			number += d;
		}
		number -= d;
		cout << number << 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