View Single Post
Old 2013-08-28, 01:27   #2
wsc811
 
Aug 2013

1002 Posts
Cool my mathematica code

d = 23*43; pell = -1; P[0] = 0; Q[0] = 1;
x[0] = (P[0] + Sqrt[d])/Q[0];
a[0] = IntegerPart[x[0]];
i = 0;
While[(x[i] != 1/(x[0] - a[0]) && P[i] != pell) || i == 1,
P[i + 1] = Q[i] a[i] - P[i];
Q[i + 1] = (d - P[i + 1]^2)/Q[i];
x[i + 1] = (P[i + 1] + Sqrt[d])/Q[i + 1];
a[i + 1] = IntegerPart[x[i + 1]];
Print[{i, Q[i], P[i], a[i]}]; i++];

i cant use code style ,have proper method?
wsc811 is offline   Reply With Quote