# 斐波那契产品

13

``````1 = 1
2 = 2
3 = 3
4 = 3 + 1
12 = 8 + 3 + 1
13 = 13
100 = 89 + 8 + 3
``````

``````1: 1
2: 2
3: 3
4: 3
5: 5
6: 5
7: 10
8: 8
9: 8
42: 272
1000: 12831
12345: 138481852236
``````

6

1
@PeterTaylor对于这个问题，我不认为负斐波那契数是该系列的一部分。连续或仅在需要索引时才重要，我们不在乎此问题的索引。
orlp

1

1
@orlp是连续的还是无关紧要的，因为两种不同的形式将给出两种不同的乘积。但是，您已经以一种已经隐式排除了连续的斐波那契项的方式说明了问题，因此不必担心。

2
（特别是：F（n）和F（n + 1）都不会出现在输出中，因为算法保证在考虑它们之前，余数已经小于F（n + 2）= F（n）+ F（n + 1））

5

# 果冻，16 15 字节

``````Rf1+Ð¡¤ṪạµÐĿIAP
``````

### 怎么运行的

``````Rf1+Ð¡¤ṪạµÐĿIAP  Main link. Argument: n (integer)

µ       Combine the chain to the left into a link.
ÐĿ     Apply that link until the results are no longer unique.
Return the list of unique results.
¤            Combine the two links to the left into a niladic chain.
1                  Set the left (and right) argument to 1.
+D¡               Apply + to the left and right argument, updating the left
argument with the sum, and the right argument with the
previous value of the left one. Return the list of results.
Repeat this process n times.
This yields n + 1 Fibonacci numbers, starting with 1, 2.
R                  Range; map k to [1, ..., k].
f                 Filter; keep the items in the range that are Fibonacci numbers.
Ṫ           Tail; yield the last one or 0 if the list is empty.
ạ          Absolute difference with k.
This is the argument of the next iteration.
I    Compute the increments of the arguments to the loop, yielding
the selected Fibonacci numbers (with changed sign).
A   Apply absolute value to each.
P  Compute their product.
``````

6

orlp

9

## Python，54个字节

``f=lambda n,a=1,b=1:n<1or b>n and a*f(n-a)or f(n,b,a+b)``

5

# Perl，69 63 + 4（`-pl61`标志）= 67字节

``````#!perl -pl61
while(\$_){\$n=\$m=1;(\$n,\$m)=(\$m,\$n+\$m)until\$m>\$_;\$_-=\$n;\$\*=\$n}}{
``````

``````> echo 42 | perl -pl61e 'while(\$_){\$n=\$m=1;(\$n,\$m)=(\$m,\$n+\$m)until\$m>\$_;\$_-=\$n;\$\*=\$n}}{'
``````

``````while (<>) {
# code above added by -p
# \$_ has input value
# \$\ = 1 by -l61
while (\$_ != 0) {
my \$n = 1;
my \$m = 1;
while (\$m <= \$_) {
(\$n, \$m) = (\$m, \$n + \$m);
}
\$_ -= \$n;
\$\ *= \$n;
}
} {
# code below added by -p
print;  # prints \$_ (undef here) and \$\
}``````

2

## JavaScript（ES6），78个 42个字节

``````f=(n,a=1,b=1)=>n?b>n?a*f(n-a):f(n,b,a+b):1
``````

@ Sp3000的答案的端口。原始的78字节版本：

``````f=(n,a=[2,1])=>n>a[0]?f(n,[a[0]+a[1],...a]):a.map(e=>e>n?0:(r*=e,n-=e),r=1)&&r
``````

2

# > <>，57字节

``````111\ ;n{/
:@+>:{:})?\\$:@@
~{*}:0=?\}>:0\${:})?\$~:{\$-\$:1@?\$
``````

`f0, f1, f2, ..., fn`在堆栈上建立斐波那契数列（），直到达到大于输入（`i`）的数字为止。然后，将产品（`p`）初始化为`1`...

``````while (i != 0)
if (fn <= i)
i = i - fn
p = p * fn
else
i = i - 0
p = p * 1
output p
``````

1

# Pyth，28个字节

``````K1WQJ0 .WgQH+Z~JZ1=*KJ=-QJ;K
``````

1

# Pyth，24个字节

``````W=-QeaYh.WgQeH,eZsZ1;*FY
``````

### 说明：

`Q` 被分配了输入编号。

``````h.WgQeH,eZsZ1
.WgQeH         while Q >= end(H):
,eZsZ       H=Z=(end(Z), sum(Z))
h               first
``````

``````1 -> (1,1) -> (1,2) -> (2,3) -> (3,5) -> (5,8) -> (8,13) -> 8
``````

``````W=-QeaY...;*FY    implicit: Y = empty list
aY...        add the calculated Fibonacci number to the empty list
e             take the last element of Y (yes the number we just added)
=-Q              and update Q with the difference of Q and ^
W         ;       continue until Q == 0
*FY    multiply all number in Y and print
``````

1

``````(a&b)c|c<1=1|b>c=a*f(c-a)|d<-a+b=b&d\$c
f=0&1
``````
• `a` 是以前的斐波那契数
• `b` 是当前的斐波那契数
• `c` 是输入
• `f` 是所需的功能

``````(a & b) c | c == 0    = 1
| c <  b    = a * f (c-a)
| otherwise = b & (a + b) \$ c
f x = (0 & 1) x
``````

1

## 其实22个位元组

``````W;╗uR♂F;`╜≥`M░M;╜-WXkπ
``````

``````W;╗uR♂F;`╜≥`M░M;╜-WXkπ
(implicit input)
W                 W     while top of stack is truthy:
;╗                       push a copy of n to reg0
uR♂F;                  push 2 copies of [Fib(a) for a in range(1, n+2)]
`╜≥`M░            filter: take values where n <= Fib(a)
M;          two copies of maximum (call it m)
╜-        subtract from n (this leaves n-m on top of the stack to be the new n next iteration, with a copy of m below it)
X    discard the 0 left over after the loop ends
kπ  product of all stack values
``````

1
@cat就像认真地一样，它使用CP437。
Mego

1

# 使用Javascript（ES6）134个106 92字节

``````n=>{for(c=[a=b=s=1,1];a+b<=n;)a+=b,c.unshift(b+=a,a);c.map(i=>i<=n&&(n-=i)&(s*=i));alert(s)}
``````

1

# 返回，44字节

``````[a:[a;][1\$[¤¤+\$a;->~][]#%\$␌a;\-a:]#␁[¤][×]#]
``````

Try it here.

``````12345[a:[a;][1\$[¤¤+\$a;->~][]#%\$␌a;\-a:]#␁[¤][×]#]!
``````

# 说明

``````[                                           ]  lambda
a:                                            store input to a
[  ][                         ]#            while loop
a;                                           check if a is truthy
1\$[¤¤+\$a;->~][]#%                        if so, generate all fibonacci numbers less than a
\$␌                      push copy of TOS to stack2
a;\-a:                a-=TOS
␁[¤][×]#   get product of stack2
``````

Mama Fun Roll

0

# PHP，119字节

``````for(\$o=\$c=1;\$c<=\$n=\$argv[1];\$f[++\$k]=\$c,\$a=\$b,\$b=\$c,\$c+=\$a);
for(\$i=\$k;\$i;\$i--)for(;\$n>=\$d=\$f[\$i];\$n-=\$d,\$o*=\$d);echo\$o;
``````

``````\$ php -d error_reporting=0 fibonacci-factors.php 100
# The output:
2136
``````

0

## Q，47字节

``````m:{*/1_-':|(0<){y-x x bin y}[*+60(|+\)\1 0]\x}
``````

``````+(i;m'i:1 2 3 4 5 6 7 8 9 42 1000 12345)
``````

``````1     1
2     2
3     3
4     3
5     5
6     5
7     10
8     8
9     8
42    272
1000  12831
12345 138481852236
``````

`n funtion\arg` n次应用function（function（function（...（function（args））））（内部使用tal递归），并返回结果序列。我们将fibonnaci系列的60个第一项计算为`*+60(|+\)\1 0`。在这种情况下，函数为（ | +）：加在序列上的+ \会计算部分和（ex + \ 1 2 3为1 3 6），|反转seq。因此，每次“迭代”时，我们都会计算前两个斐波那契数的部分和，并返回部分求和后求和，`60(|+\)\1 0`生成序列1 0，1 1，2 1，3 `*+`2，5 3，8 5，13 8，21 13，... 应用于结果翻转（置位）并取第一个，结果为序列1 1 2 3 5 8 13 21 34 55 ..

`(cond)function\args` 在cond true时应用function（function（.. function（args））），并返回部分结果的序列

`function[arg]` 在一个以上参数的函数上应用会创建一个投影（部分应用）

`{y-x x bin y}[*+60(|+\)\1 0]`声明带有部分投影的args x，y的lambda（arg x是斐波那契数列，计算为* + 60（| +）\ 1 0）。x代表斐波那契值，y代表要处理的数字。二进制搜索（bin）用于定位更大的斐波那契数<= y（`x bin y`）的索引，并减去x的对应值。

``````f:*+60(|+\)\1 0;m:{*/1_-':|(0<){x-f f bin x}\x}    /new version
``````