一生几回质数年

(1)

ZY 发给我一行代码：

mosaicCalc::D(sin(x) ~ x)
## function (x)
## cos(x)

ZY 被噎住了。然而没多久，就发给我另一行代码：

mosaicCalc::antiD(a * x ^ 2 ~ x, a = 3)
## function (x, a = 3, C = 0)
## a * 1/3 * x^3 + C

D(expression(sin(x)), "x")
## cos(x)

R 语言会做分解质因数吗？

(3)

library(gmp)
factorize(2012)
## Big Integer ('bigz') object of length 3:
## [1] 2   2   503

factorize(2021)
## Big Integer ('bigz') object of length 2:
## [1] 43 47

2021 居然是个半质数！只能分解成两个质因数 43 和 47！而且这一对宝贝还是一对相邻的质数！而且 20 和 21 本身还是相邻的整数！

year <- 1980:2079
year_p <- sapply(year, factorize)
n_p <- sapply(year_p, length)
year_print <- paste(year, sapply(year_p, paste, collapse = ' x '), sep = ' = ')

year[n_p == 1]
##  [1] 1987 1993 1997 1999 2003 2011 2017 2027 2029 2039 2053 2063 2069

year[n_p == 2]
##  [1] 1981 1982 1983 1985 1991 1994 2005 2018 2019 2021 2026 2031 2033 2038 2041
## [16] 2042 2045 2047 2049 2051 2059 2062 2066 2071 2073 2077 2078

附录

year_print
##   [1] "1980 = 2 x 2 x 3 x 3 x 5 x 11"
##   [2] "1981 = 7 x 283"
##   [3] "1982 = 2 x 991"
##   [4] "1983 = 3 x 661"
##   [5] "1984 = 2 x 2 x 2 x 2 x 2 x 2 x 31"
##   [6] "1985 = 5 x 397"
##   [7] "1986 = 2 x 3 x 331"
##   [8] "1987 = 1987"
##   [9] "1988 = 2 x 2 x 7 x 71"
##  [10] "1989 = 3 x 3 x 13 x 17"
##  [11] "1990 = 2 x 5 x 199"
##  [12] "1991 = 11 x 181"
##  [13] "1992 = 2 x 2 x 2 x 3 x 83"
##  [14] "1993 = 1993"
##  [15] "1994 = 2 x 997"
##  [16] "1995 = 3 x 5 x 7 x 19"
##  [17] "1996 = 2 x 2 x 499"
##  [18] "1997 = 1997"
##  [19] "1998 = 2 x 3 x 3 x 3 x 37"
##  [20] "1999 = 1999"
##  [21] "2000 = 2 x 2 x 2 x 2 x 5 x 5 x 5"
##  [22] "2001 = 3 x 23 x 29"
##  [23] "2002 = 2 x 7 x 11 x 13"
##  [24] "2003 = 2003"
##  [25] "2004 = 2 x 2 x 3 x 167"
##  [26] "2005 = 5 x 401"
##  [27] "2006 = 2 x 17 x 59"
##  [28] "2007 = 3 x 3 x 223"
##  [29] "2008 = 2 x 2 x 2 x 251"
##  [30] "2009 = 7 x 7 x 41"
##  [31] "2010 = 2 x 3 x 5 x 67"
##  [32] "2011 = 2011"
##  [33] "2012 = 2 x 2 x 503"
##  [34] "2013 = 3 x 11 x 61"
##  [35] "2014 = 2 x 19 x 53"
##  [36] "2015 = 5 x 13 x 31"
##  [37] "2016 = 2 x 2 x 2 x 2 x 2 x 3 x 3 x 7"
##  [38] "2017 = 2017"
##  [39] "2018 = 2 x 1009"
##  [40] "2019 = 3 x 673"
##  [41] "2020 = 2 x 2 x 5 x 101"
##  [42] "2021 = 43 x 47"
##  [43] "2022 = 2 x 3 x 337"
##  [44] "2023 = 7 x 17 x 17"
##  [45] "2024 = 2 x 2 x 2 x 11 x 23"
##  [46] "2025 = 3 x 3 x 3 x 3 x 5 x 5"
##  [47] "2026 = 2 x 1013"
##  [48] "2027 = 2027"
##  [49] "2028 = 2 x 2 x 3 x 13 x 13"
##  [50] "2029 = 2029"
##  [51] "2030 = 2 x 5 x 7 x 29"
##  [52] "2031 = 3 x 677"
##  [53] "2032 = 2 x 2 x 2 x 2 x 127"
##  [54] "2033 = 19 x 107"
##  [55] "2034 = 2 x 3 x 3 x 113"
##  [56] "2035 = 5 x 11 x 37"
##  [57] "2036 = 2 x 2 x 509"
##  [58] "2037 = 3 x 7 x 97"
##  [59] "2038 = 2 x 1019"
##  [60] "2039 = 2039"
##  [61] "2040 = 2 x 2 x 2 x 3 x 5 x 17"
##  [62] "2041 = 13 x 157"
##  [63] "2042 = 2 x 1021"
##  [64] "2043 = 3 x 3 x 227"
##  [65] "2044 = 2 x 2 x 7 x 73"
##  [66] "2045 = 5 x 409"
##  [67] "2046 = 2 x 3 x 11 x 31"
##  [68] "2047 = 23 x 89"
##  [69] "2048 = 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2"
##  [70] "2049 = 3 x 683"
##  [71] "2050 = 2 x 5 x 5 x 41"
##  [72] "2051 = 7 x 293"
##  [73] "2052 = 2 x 2 x 3 x 3 x 3 x 19"
##  [74] "2053 = 2053"
##  [75] "2054 = 2 x 13 x 79"
##  [76] "2055 = 3 x 5 x 137"
##  [77] "2056 = 2 x 2 x 2 x 257"
##  [78] "2057 = 11 x 11 x 17"
##  [79] "2058 = 2 x 3 x 7 x 7 x 7"
##  [80] "2059 = 29 x 71"
##  [81] "2060 = 2 x 2 x 5 x 103"
##  [82] "2061 = 3 x 3 x 229"
##  [83] "2062 = 2 x 1031"
##  [84] "2063 = 2063"
##  [85] "2064 = 2 x 2 x 2 x 2 x 3 x 43"
##  [86] "2065 = 5 x 7 x 59"
##  [87] "2066 = 2 x 1033"
##  [88] "2067 = 3 x 13 x 53"
##  [89] "2068 = 2 x 2 x 11 x 47"
##  [90] "2069 = 2069"
##  [91] "2070 = 2 x 3 x 3 x 5 x 23"
##  [92] "2071 = 19 x 109"
##  [93] "2072 = 2 x 2 x 2 x 7 x 37"
##  [94] "2073 = 3 x 691"
##  [95] "2074 = 2 x 17 x 61"
##  [96] "2075 = 5 x 5 x 83"
##  [97] "2076 = 2 x 2 x 3 x 173"
##  [98] "2077 = 31 x 67"
##  [99] "2078 = 2 x 1039"
## [100] "2079 = 3 x 3 x 3 x 7 x 11"