Ryan22oct's blog

By Ryan22oct, history, 12 hours ago, In English

Hi friends,please help me solve this if you have some spare time :)

a[1]-2*x[1]+x[n]=m;

a[2]-2*x[2]+x[1]=m;

a[3]-2*x[3]+x[2]=m;

. . .

a[n]-2*x[n]+x[n-1]=m;

here the array a is given and the constant m is also given,we have to find out the values of all the xi's in my approach i applied binary search on the value of x[n]..so lets suppose the assumed value of x[n]=mid then after solving the equation if i will get the value of x[n]>mid then i will reduce the mid,else increase the mid till the value of x[n] found out==mid...the problem here is that i have to find out an integral solution of the equations(if it exists)..so while solving the equations if some x[i] comes out to be a fractional value then we cannot proceed further with that value of mid..so if this happens then the current mid isnt a solution..now what should be the next mid value?increase/decrease or adjust it differently to converge to an integer solution(if it exists)?

last question:is there some other way in which this problem can be solved?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
12 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Ryan22oct (previous revision, new revision, compare).

»
11 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I think this problem definitely has mathematics solution, but it will be a bit hard to find it. If x can't be too big integer, you can just try every x (for(int x = 1; x <= ...; ++x))

»
10 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Since $$$a_i=2x_i-x_{i-1}+m$$$, this means $$$2^{i-1}a_i=2^ix_i-2^{i-1}x_{i-1}+2^{i-1}m$$$, so adding for $$$i=1$$$ to $$$i=n$$$ gives $$$a_1+2a_2+4a_3+\cdots+2^{n-1}a_n=(2^n-1)x_n+(2^n-1)m$$$, so you can solve for $$$x_n$$$.