官术网_书友最值得收藏!

15. Prime tuples

Mathematicians like playing with prime numbers, so they have come up with several different names for groupings of related primes:

  • Twin primes are primes {p, p + 2} that differ by two, such as {3, 5}. (Primes that differ by only 1 are not very interesting because 2 and 3 are the only primes that differ by 1.)
  • Cousin primes are primes {p, p + 4} that differ by 4, such as {3, 7}.
  • Sexy primes are primes {p, p + 6} that differ by 6, such as {5, 11}. (The name sexy primes is a pun because sex is Latin for six.)

You can also look for different numbers of primes with various spacings. For example, you can look for sexy pairs, sexy triples such as {7, 13, 19}, and so forth.

Write a program that checks numbers up to a maximum value, looking for primes with a given spacing and quantity. For example, the user might set the spacing to six and the number to 3 to look for groups of three primes that are each six apart, such as {5, 11, 17}.

Use your program to see what's special about groups of three or four primes that differ by 6, 12, 18, and other multiples of 3.

主站蜘蛛池模板: 德兴市| 曲周县| 桂林市| 临江市| 台东县| 新乡县| 南皮县| 宁明县| 东海县| 大关县| 大余县| 普定县| 同仁县| 五原县| 大安市| 平山县| 繁昌县| 洪湖市| 南宁市| 潼关县| 化德县| 遵化市| 财经| 贵南县| 常德市| 白沙| 涟水县| 台东市| 黎平县| 鹤壁市| 巴南区| 铜鼓县| 克山县| 三原县| 长沙县| 垣曲县| 北海市| 九江市| 若羌县| 乳山市| 根河市|