Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
空间换时间#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator