此序列的偶数和奇数的独特公式

Unique formula for even and odd for this sequence

在编译我的代码之前,我在生成通用公式时卡住了。谁能帮我算出下面数列的通式?

when n=3 the value is 0
when n=4 the value is 1
when n=5 the value is 0
when n=6 the value is -1
when n=7 the value is 0
when n=8 the value is 1
when n=9 the value is 0
when n=10 the value is-1
when n=11 the value is 0
when n=12 the value is 1
when n=13 the value is 0
 when n=14 the value is -1 etc

我得到了部分公式,但我无法确定我的问号 (???) 所在的位置,

|(-1)^n -1|/2 + (-1)^[n(???/2)]

这似乎更简单(无论如何对我来说):

((n+1)%2)*(2-(n+1)%4)

希望这能满足您的要求,

( (-1)^n + (1)^n )/2 *((-1)^(n/2))

intuition,
        -1  for n=6,10,14 ..
        0   for n=3,5,7,9 .. 
        1   for n=4,8,12 .. 

只要幂为奇数,第一项就会减为零。 在偶数次方的情况下,我们观察到 -1n/2 次方为奇数次。

这是众多公式中的一个通用公式,它利用了序列的周期性。

See the sequence on OEIS (A056594)


另一种表示方式更符合您的尝试,是使用两个“指标”,第一个处理奇偶校验,第二个处理每个偶数的符号。