<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)