Determinant Fun

Let MN = (mij) be an N × N matrix, with integer constants Q, K, A, B satisfying: mij =Acos((i+Qj)x)+Bsin((i+Qj)x), where0≤i,j<N, withx=KNπ. Given an integer interval [L, R], compute ∑R det(I + MN ) N=L where I is the identity matrix, and det is the determinant of a square matrix. Input A number of of inputs (≤ 1000), each line with integers Q, K, A, B, L, R. They satisfy, 0 < K,A,B,L,R ≤ 109, 0 < L ≤ R ≤ 109, |Q| ≤ 1. Additionally, if Q = 0 and K is odd, then R−L ≤ 300. Output For each input, output the answer on one line, rounded to 6 digits after the decimal. Sample Input -1 12 10 8 3 10 1 13 7 9 3 10 0 11 10 7 3 10 Sample Output 13607.000000 -12342.000000 57.083113