Give an arithmetic difference series and ask what is the nth Prime Number of this arithmetic difference series.
Train of Thought: This question mainly tests how to screen prime numbers and linear screen. For details, see the code.
Code:
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define Max 1000010 using namespace STD; int prime [Max], PRIMES; bool notp [Max]; int A, D, N; void pretreatment () {notp [1] = true; For (INT I = 2; I <Max; ++ I) {If (! Notp [I]) prime [++ primes] = I; for (Int J = 1; j <= primes & I * prime [J] <Max; ++ J) {notp [I * prime [J] = true; if (I * prime [J] = 0) Break ;}} int main () {pretreatment (); while (scanf ("% d", & A, & D, & N), A + D + n) {for (INT now = ;; now + = d) {If (! Notp [now]) -- N; If (! N) {printf ("% d \ n", now); break ;}}return 0 ;}
Poj 3006 Dirichlet's Theorem on arithmetic progressions fast screening Prime Number