受此Math.SE问题的启发。
背景
的斐波纳契数列(称为F
)是序列,开始0, 1
使得每个号码(F(n)
)(前两个后)是两个前(总和F(n) = F(n-1) + F(n-2)
)。
斐波那契数列mod K(称为M
)是斐波那契数列mod K()的序列M(n) = F(n) % K
。
可以证明,斐波那契数列对所有K都是循环的,因为每个值都是由前一对确定的,并且只有K 2个可能的非负整数对都小于K。因为斐波那契数列K在第一个重复的术语对之后是循环的,在第一个重复的术语对之前从未出现在Fibonacci序列mod K中的数字将永远不会出现。
对于K = 4
0 1 1 2 3 1 0 1 ...
对于K = 8
0 1 1 2 3 5 0 5 5 2 7 1 0 1 ...
请注意,对于K = 8,4和6不会出现在重复出现之前0 1
,因此4和6将永远不会出现在斐波那契数列mod 8中。
挑战
给定严格大于0的整数K,输出所有未出现在Fibonacci序列mod K中的小于K的非负整数。
规则
您可以假设K将适合您的本机整数类型(在reason内)。
如果斐波那契序列模K中没有出现小于K的非负数,则您的程序/函数应以任何合理的方式输出所有此类负数。
如果在Fibonacci Sequence mod K中没有出现不小于K的非负整数,则您的程序/函数可能会通过返回空列表,不打印任何内容,产生错误等来指示这一点。
顺序无所谓。
这是代码高尔夫球,因此每种语言的最短答案都会获胜。
测试用例
非空测试用例
8 [4, 6]
11 [4, 6, 7, 9]
12 [6]
13 [4, 6, 7, 9]
16 [4, 6, 10, 12, 14]
17 [6, 7, 10, 11]
18 [4, 6, 7, 9, 11, 12, 14]
19 [4, 6, 7, 9, 10, 12, 14]
21 [4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 19]
22 [4, 6, 7, 9, 15, 17, 18, 20]
23 [4, 7, 16, 19]
24 [4, 6, 9, 11, 12, 14, 15, 18, 19, 20, 22]
26 [4, 6, 7, 9, 17, 19, 20, 22]
28 [10, 12, 14, 16, 18, 19, 23]
29 [4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 27]
31 [4, 6, 9, 12, 14, 15, 17, 18, 19, 22, 25, 29]
32 [4, 6, 10, 12, 14, 18, 20, 22, 26, 28, 30]
33 [4, 6, 7, 9, 15, 17, 18, 20, 24, 26, 27, 28, 29, 31]
34 [4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 27, 28, 30]
36 [4, 6, 7, 9, 10, 11, 12, 14, 16, 18, 20, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32]
37 [9, 10, 14, 17, 20, 23, 27, 28]
38 [4, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 36]
39 [4, 6, 7, 9, 15, 17, 19, 20, 22, 24, 30, 32, 33, 35]
...
200 [4, 6, 12, 14, 20, 22, 28, 30, 36, 38, 44, 46, 52, 54, 60, 62, 68, 70, 76, 78, 84, 86, 92, 94, 100, 102, 108, 110, 116, 118, 124, 126, 132, 134, 140, 142, 148, 150, 156, 158, 164, 166, 172, 174, 180, 182, 188, 190, 196, 198]
...
300 [6, 18, 30, 42, 54, 66, 78, 90, 102, 114, 126, 138, 150, 162, 174, 186, 198, 210, 222, 234, 246, 258, 270, 282, 294]
...
400 [4, 6, 10, 12, 14, 20, 22, 26, 28, 30, 36, 38, 42, 44, 46, 52, 54, 58, 60, 62, 68, 70, 74, 76, 78, 84, 86, 90, 92, 94, 100, 102, 106, 108, 110, 116, 118, 122, 124, 126, 132, 134, 138, 140, 142, 148, 150, 154, 156, 158, 164, 166, 170, 172, 174, 180, 182, 186, 188, 190, 196, 198, 202, 204, 206, 212, 214, 218, 220, 222, 228, 230, 234, 236, 238, 244, 246, 250, 252, 254, 260, 262, 266, 268, 270, 276, 278, 282, 284, 286, 292, 294, 298, 300, 302, 308, 310, 314, 316, 318, 324, 326, 330, 332, 334, 340, 342, 346, 348, 350, 356, 358, 362, 364, 366, 372, 374, 378, 380, 382, 388, 390, 394, 396, 398]
...
空测试用例(无输出,错误,空列表等是可接受的输出)
1, 2, 3, 4, 5, 6, 7, 9, 10, 14, 15, 20, 25, 27, 30, 35 ... 100 ...