ARTICLE AD BOX
Example:
i = 292893227695 j = 8*i**2 + 1 k = math.sqrt(j) print(j) print(k) print(k.is_integer())gives output
686291542636760920104201 828427149867.0 Trueeven though k is not an integer.
More generally, I'm trying to solve Problem 100 in Project Euler

This might be a bad strategy in general, because the numbers are so large, but still interested in what to do specifically about this problem with large numbers.
Full code below. I tried importing getcontext but that didn't seem to change anything:
import math from time import perf_counter from decimal import Decimal, getcontext getcontext().prec = 50 start = perf_counter() n = 7 # question specifies 12 (10**12) limit = 10**n # starts to slow at 7 startno = 1 #292893220000 #2.9*10**11 # squares = set() # for i in range(1,limit): # squares.add(i**2) candidates = [] for i in range(startno,limit): j = (8*i**2 + 1) k = math.sqrt(j) if k.is_integer() == True: b = ((2*i + 1) + k ) / 2 candidates.append((b,i)) print(b,i,b/(b+i)) if b + i > 10**12 and b.is_integer() == True: print(b,i) break # print(candidates) # print(len(squares)) end = perf_counter() print(end-start, n) # need to find some way to find the answers. these methods all failing due to rounding in python print(math.sqrt(285700000000)) i = 292893227695 j = 8*i**2 + 1 print(j) k = math.sqrt(j) print(k) print(k.is_integer())