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

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.

主站蜘蛛池模板: 福安市| 杭锦旗| 安阳县| 蒙阴县| 奉新县| 延津县| 玛曲县| 延川县| 蓝山县| 富裕县| 波密县| 冕宁县| 梓潼县| 白山市| 鹰潭市| 赤峰市| 渭南市| 灵川县| 闽清县| 游戏| 郓城县| 景谷| 太和县| 客服| 安国市| 天台县| 海南省| 通渭县| 吉木萨尔县| 安乡县| 阳朔县| 景泰县| 乾安县| 富锦市| 当涂县| 法库县| 泗阳县| 兴海县| 铜川市| 当雄县| 新昌县|