GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — integer_factorization_algorithms/euler.py at main · daedalus/integer_factorization_algorithms Expand file tree/ Copy patheuler.pyMore file actions 34 lines (31 loc) · 1.1 KB / Copy patheuler.pyFile metadata and controls34 lines (31 loc) · 1.1 KB 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 # /usr/bin/env python # code taken from https://maths.dk/teaching/courses/math357-spring2016/projects/factorization.pdf from gmpy2 import gcd, isqrt def euler(self, n): if n % 2 == 0: return (n / 2, 2) if n > 2 else (2, 1) end = isqrt(n) a = 0 solutionsFound = [] firstb = -1 while a < end and len(solutionsFound) < 2: bsquare = n - a ** 2 if bsquare > 0: b = isqrt(bsquare) if (b ** 2 == bsquare) and (a != firstb) and (b != firstb): firstb = b solutionsFound.append([int(b), a]) a += 1 if len(solutionsFound) < 2: return -1 a = solutionsFound[0][0] b = solutionsFound[0][1] c = solutionsFound[1][0] d = solutionsFound[1][1] k = gcd(a - c, d - b) h = gcd(a + c, d + b) m = gcd(a + c, d - b) l = gcd(a - c, d + b) n = (k ** 2 + h ** 2) * (l ** 2 + m ** 2) return [int(k ** 2 + h ** 2) // 2, int(l ** 2 + m ** 2) // 2] print(euler(int(sys.argv[1]))) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |