go = False for i,(fact,num) in enumerate(f): if c[i] < num: c[i] += 1 m *= fact go = True break m //= fact**num c[i] = 0 def rad(a, b, c, R): s = (a+b+c)/2 return ((s-a)*(s-b)*(s-c)/s) <= R*R R = 1053779 divs = getdivs(4*R) # For factor() I, J, K = 0, 0, 0 # Solve diophantine equation b^2+c^2-b*c=a^2 <=> (2b-c)^2-a^2=-3*c^2 for c in range(1, int(6*R/3**.5)): for u in gendivs(divs, c): v = -3*c*c//u if (u-v)&3: continue x, a = (u+v)//2, (u-v)//4 if (x+c)&1: continue b = (x+c)//2 if a<b and rad(a,b,c,R): I += 1 if I % 100000 == 0: print(I) print(I)
f = list(c.items()) c, go, m = [0]*len(f), True, 1 while go: yield m go = False for i,(fact,num) in enumerate(f): if c[i] < num: c[i] += 1 m *= fact go = True break m //= fact**num c[i] = 0 N, P, ok, done = 120000, defaultdict(set), set(), set() divs = getdivs(N//2) # For factor() # Solve diophantine equation p^2+r^2+p*r=y^2 <=> (2r+p)^2-y^2=-3*p^2 for p in range(1, N//2): for u in gendivs(divs, p): v = -3*p*p//u if (u-v)&3 or u+v<4*p: continue r = (u+v-2*p)//4 if r<N: P[p].add(r) ok.add((p,r)) for p in P: if len(P[p]) < 2: continue for q,r in combinations(sorted(P[p]), 2): if (q,r) in ok:
from primes import getdivs, factsum N = 10 ** 6 divs = getdivs(N) visited = set() best = (0, 0) for n in range(2, N + 1): (i, p, chain) = (n, {}, []) while i > 1 and i <= N and i not in visited: visited.add(i) p[i] = len(chain) chain.append(i) i = factsum(divs, i) - i # next if i in p: best = max(best, (len(chain) - p[i], min(chain[p[i] :]))) print(best)