最近有很多与质数/素数分解相关的挑战,所以我认为走另一条路可能很有趣。
鉴于:
- 一个正整数
n
,和 - 正整数的非空列表
f
编写一个完整的程序或函数以找到最小的整数i
,使得i >= n
和i
是f
。中元素的非负整数幂的乘积。
例子:
假设
n = 11, f = [2, 3, 5]
。前几个产品是:
1 = 2^0 * 3^0 * 5^0 2 = 2^1 * 3^0 * 5^0 3 = 2^0 * 3^1 * 5^0 5 = 2^0 * 3^0 * 5^1 4 = 2^2 * 3^0 * 5^0 6 = 2^1 * 3^1 * 5^0 10 = 2^1 * 3^0 * 5^1 9 = 2^0 * 3^2 * 5^0 15 = 2^0 * 3^1 * 5^1 25 = 2^0 * 3^0 * 5^2 8 = 2^3 * 3^0 * 5^0 12 = 2^2 * 3^1 * 5^0 => smallest greater than (or equal to) 11, so we output it. 20 = 2^2 * 3^0 * 5^1 18 = 2^1 * 3^2 * 5^0 30 = 2^1 * 3^1 * 5^1 50 = 2^1 * 3^0 * 5^2 27 = 2^0 * 3^3 * 5^0 45 = 2^0 * 3^2 * 5^1 75 = 2^0 * 3^1 * 5^2 125 = 2^0 * 3^0 * 5^3
假设
n=14, f=[9, 10, 7]
。同样,前几个产品:
1 = 7^0 * 9^0 * 10^0 7 = 7^1 * 9^0 * 10^0 9 = 7^0 * 9^1 * 10^0 10 = 7^0 * 9^0 * 10^1 49 = 7^2 * 9^0 * 10^0 => smallest greater than (or equal to) 14, so we output it. 63 = 7^1 * 9^1 * 10^0 70 = 7^1 * 9^0 * 10^1 81 = 7^0 * 9^2 * 10^0 90 = 7^0 * 9^1 * 10^1 100 = 7^0 * 9^0 * 10^2
测试用例:
n, f -> output
10, [2, 3, 5] -> 10
17, [3, 7] -> 21
61, [3,5,2,7] -> 63
23, [2] -> 32
23, [3] -> 27
23, [2, 3] -> 24
31, [3] -> 81
93, [2,2,3] -> 96
91, [2,4,6] -> 96
1, [2,3,5,7,11,13,17,19] -> 1
151, [20,9,11] -> 180
11616, [23,32] -> 12167
11616, [23,32,2,3] -> 11664 = 2^4 * 3^6
5050, [3,6,10,15,21,28,36,45,55,66,78,91,105,120,136,153,171,190,210] -> 5103 = 3^6 * 7
12532159, [57, 34, 12, 21] -> 14183424 = 12^5 * 57
规则
- 您可能会假设
f
它将包含至少一个元素,并且的所有元素都f
将大于1。 - 如果需要,您可以选择假定该列表
f
按降序/升序排序(但请指定)。 - 您可以根据需要选择元素的数量
f
。 - 允许输出为字符串。
- 这是代码高尔夫球,因此每种语言的最短答案以字节为单位!
- 默认的I / O规则适用,并且禁止标准漏洞。
- 鼓励解释。
∞
保存3
字节,-Log@0 (doesn't work on TIO, but works fine on desktop Mathematica). Also,
该字节短于Length@{##}
。