Description
If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing by d, i.e., a, a + d, a + 2d, a + 3d, a + 4d, ..., contains infinitely many prime numbers. This fact is known as Dirichlet's Theorem on Arithmetic Progressions, which had been conjectured by Johann Carl Friedrich Gauss (1777 - 1855) and was proved by Johann Peter Gustav Lejeune Dirichlet (1805 - 1859) in 1837.
For example, the arithmetic sequence beginning with 2 and increasing by 3, i.e.,
2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, ... ,
contains infinitely many prime numbers
2, 5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89, ... .
Your mission, should you decide to accept it, is to write a program to find the nth prime number in this arithmetic sequence for given positive integ
Dirichlet‘s Theorem on Arithmetic Progressions
这篇博客介绍了Dirichlet定理,即在互质的两个正整数a和d组成的等差数列中存在无穷多个质数。文章通过示例解释定理,并提供了一个编程任务,要求编写程序找到该等差数列中第n个质数。还给出了样例输入和输出,并分享了实现算法的思路,包括为何放弃使用质数数组而选择使用标志数组来标记质数。
摘要由CSDN通过智能技术生成