Spaces:
Sleeping
Sleeping
File size: 1,777 Bytes
e3af2b1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import time, sys
sys.set_int_max_str_digits(0)
st = int(input("start? "))
en = int(input("end? "))
se = int(input("step? "))
size = int(input("size? "))
xQ = input("show x values?(y/n) ")
with open('Result.txt', 'w', encoding='utf8') as f:
for S in range(st, en + 1, se):
MaxN = size
X = [[2, 1]]
AminB = []
for i in range(1, MaxN + 1):
Temp = [[X[i-1][0] ** 2, X[i-1][1] * X[i-1][0]], [X[i-1][1] * X[i-1][1] * S, X[i-1][1] * X[i-1][0]]]
if X[i-1][1] == 1 and (int(Temp[1][0] / 2) == Temp[1][0] / 2 and int(Temp[1][1] / 2) == Temp[1][1] / 2 and int(Temp[0][0] / 2) == Temp[0][0] / 2 and int(Temp[0][1] / 2) == Temp[0][1] / 2):
while True:
if Temp[1][0] % 2 == 0 and Temp[1][1] % 2 == 0 and Temp[0][0] % 2 == 0 and Temp[0][1] % 2 == 0:
Temp[0][0] //= 2
Temp[0][1] //= 2
Temp[1][0] //= 2
Temp[1][1] //= 2
else:
break
AminB.append(Temp[0][0] - Temp[1][0])
res = [Temp[0][0] + Temp[1][0], (Temp[0][1] * 2)]
while True:
if res[0] % 2 == 0 and res[1] % 2 == 0:
res[0] //= 2
res[1] //= 2
else:
break
X.append(res)
f.write('S = '+ str(S) + '\n')
if xQ == 'y':
f.write('x = ')
for i in X:
f.write(str(i[0]) + '/' + str(i[1]) + ', ')
f.write('\n')
f.write('A-B = ')
for i in AminB:
f.write(str(i) + ', ')
f.write('\n\n')
print('Complete!')
time.sleep(3) |