老师让菲菲从 1 ~ 9 这9个数字中选取 4 个不同的数字,组成一个四位数,使得这个四位数能被所有她没有选中的数整除,但不能被选中的任一个数字整除。那么,菲菲组成的四位数是_____。
for (num in seq(1234, 9876)){
contained = strsplit(as.character(num), split = "")[[1]] |>
unique() |>
as.integer()
if (length(contained) != 4 | 0 %in% contained) next
if (any(num %% contained == 0)) next
other = (1:9)[!1:9 %in% contained]
if (any(num %% other != 0)) next
print(num)
## [1] 5936
如果您使用了本文的内容,请按照以下方式引用:
gaoch (2023). 一道数学题. BIO-SPRING. /post/2023/12/31/a-math-quiz/
BibTeX citation
@misc{
title = "一道数学题",
author = "gaoch",
year = "2023",
journal = "BIO-SPRING",
note = "/post/2023/12/31/a-math-quiz/"