传送门
题意:
给你一个序列a,对于数,将其写成任意个连续的数,记第组数的和为,现要你找出所有的的组合,使每个组合中的sum的和为0。
思路:
经过推理,不难发现:
对于为偶数的情况,它的贡献为,k为任意整数,下同;
对于为奇数的情况,它的贡献为。
同时,我们也可以得出第一个重要结论:当选取的全为奇数时,一定合法。
继续推理可得出下一个结论:**当选取的至少有一个奇数时,一定合法。*,证明如下:
记我们选取的数的集合为,且其中存在x个奇数,要证明选取的数合法,
即证明:=这个式子成立
而等式右边的式子又可以等价于:gcd()*k,这一步不多做阐述,
即要证明:=gcd()*k,
记S =
即证明:gcd() | S/2
易得:gcd() | S且由于中存在奇数,因而gcd() 一定不能整除2,所以gcd() | S/2一定成立,
证毕。
接下来看全为偶数的情况,先说结论:我们将所有的偶数写为的形式,则选取的序列满足其中k值最小的数为偶数时,就合法。
证明如下:
同样是上面的那个式子:gcd() | S/2,现在b序列全为偶数,将其中每个数都写为的形式,设最小的k为,把gcd()也写为上述形式,则其等于,且x一定为奇数,不难得出x | S/2,现在只需要证明: | S/2,我们将S/2拆成序列的形式来看就是:{},在这个除以2之后的序列中,原来刚好包含的数都变为了包含的数,而如果这些的个数为奇数,那么再让其除以则会出现小数,而如果个数为偶数,那么就可以让每两个合并为一个,即:选取的序列满足其中k值最小的数为偶数时,就合法。
证毕。
最后的答案就用上面的结论即可得出。