<LʒfåP
将整数作为第一个输入,列表作为第二个。1
在输出中包括可选项。
在线尝试或验证所有测试用例。
说明:
< # Decrease the (implicit) input by 1
L # Create a list in the range [1,input-1]
ʒ # Filter it by:
f # Get all prime factors of the current number (without duplicates)
å # Check for each if its in the (implicit) input-list
P # And check if this is truthy for all
# (after the filter, the result is output implicitly)
@Grimy提供的两个6 字节替代方案:
GNfåP–
在线尝试。
G # Loop `N` in the range [1, (implicit) input):
Nf # Get all prime factors of `N` (without duplicates)
å # Check for each if its in the (implicit) input-list
P # And check if this is truthy for all
– # If it is, output the current `N` with trailing newline
这很慢([2,5,7], 15
测试用例已经超时),但是不像其他两种方法那样:
sиPÑʒ›
与上面的其他两个程序不同,它将列表作为第一个输入,将整数作为第二个输入。不过,它的确1
在输出中包括了可选的。
在线尝试。
s # Swap so the stack is now [list-input, integer-input]
и # Repeat the list (flattened) the integer amount of times
# i.e. [2,5] and 10 → [2,5,2,5,2,5,2,5,2,5,2,5,2,5,2,5,2,5,2,5]
P # Take the product of this list
# → 10000000000
Ñ # Get all divisors of this integer
# (the bottleneck for larger integers in this approach)
# → [1,2,4,5,8,10,16,20,25,32,40,50,64,80,100,125,128,160,200,250,256,320,400,500,512,625,640,800,1000,1024,1250,1280,1600,2000,2500,2560,3125,3200,4000,5000,5120,6250,6400,8000,10000,12500,12800,15625,16000,20000,25000,25600,31250,32000,40000,50000,62500,64000,78125,80000,100000,125000,128000,156250,160000,200000,250000,312500,320000,390625,400000,500000,625000,640000,781250,800000,1000000,1250000,1562500,1600000,1953125,2000000,2500000,3125000,3200000,3906250,4000000,5000000,6250000,7812500,8000000,9765625,10000000,12500000,15625000,16000000,19531250,20000000,25000000,31250000,39062500,40000000,50000000,62500000,78125000,80000000,100000000,125000000,156250000,200000000,250000000,312500000,400000000,500000000,625000000,1000000000,1250000000,2000000000,2500000000,5000000000,10000000000]
ʒ # Filter these divisors:
› # And only keep those where the (implicit) input-integer is larger than the divisor
# → [1,2,4,5,8]
# (after the filter, the result is output implicitly)