Last time I 've post a problem as follow : Given two positives integers p and q , Generates the longest possible sequence of integer numbers which sum of any p consecutive is positive and sum of any q consecutive is negative.
I 've got the solutions but I 'm not sure if it 's right or not. Can anyone verify the following method?
First : The length of the sequence is less than p + q - gcd(p,q) for sure (Anyone who want to know how to prove this please mail me)
To simplify the problem add another variable n ( = length of the sequence) for the given numbers n,p and q ,this problem can be modeled as a system of equations. for example if (n,p,q) = (5,3,4) the following equations will solve the problem. Let the sequence be x,x,x,...,x The equations are x+x+x = c1 x+x+x = c2 x+x+x = c3 x+x+x+x = -c4 x+x+x+x = -c5
and c1,c2,...,c5 are positive integers I 've tried to solve this problem by programming. I 've found it works for arbitary value of c1,c2,c3,c4 and c5. And as far as I 've tested my program I 've found that the longest possible length is always = p + q - gcd(p,q) - 1. But anyway I couldn't prove that arbitary positive integers can be used for ci and the longest possible length is as I 's mentioned. Can anyone verify it? Or is there a better way to solve this problem?